use of org.olat.course.properties.CoursePropertyManager in project openolat by klemens.
the class LTIRunController method checkHasDataExchangeAccepted.
/**
* Helper method to check if user has already accepted. this info is stored
* in a user property, the accepted values are stored as an MD5 hash (save
* space, privacy)
*
* @param hash
* MD5 hash with all user data
* @return true: user has already accepted for this hash; false: user has
* not yet accepted or for other values
*/
private boolean checkHasDataExchangeAccepted(String hash) {
boolean dataAccepted = false;
CoursePropertyManager propMgr = this.userCourseEnv.getCourseEnvironment().getCoursePropertyManager();
Property prop = propMgr.findCourseNodeProperty(this.courseNode, getIdentity(), null, PROP_NAME_DATA_EXCHANGE_ACCEPTED);
if (prop != null) {
// compare if value in property is the same as calculated today. If not, user as to accept again
String storedHash = prop.getStringValue();
if (storedHash != null && hash != null && storedHash.equals(hash)) {
dataAccepted = true;
} else {
// remove property, not valid anymore
propMgr.deleteProperty(prop);
}
}
return dataAccepted;
}
use of org.olat.course.properties.CoursePropertyManager in project openolat by klemens.
the class ForumCourseNodeWebService method addMessage.
/**
* Internal helper method to add a message to a forum.
* @param courseId
* @param nodeId
* @param parentMessageId can be null (will lead to new thread)
* @param title
* @param body
* @param identityName
* @param isSticky only necessary when adding new thread
* @param request
* @return
*/
private Response addMessage(Long courseId, String nodeId, Long parentMessageId, String title, String body, String identityName, Boolean isSticky, HttpServletRequest request) {
if (!isAuthor(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
BaseSecurity securityManager = BaseSecurityManager.getInstance();
Identity identity;
if (identityName != null) {
identity = securityManager.findIdentityByName(identityName);
} else {
identity = RestSecurityHelper.getIdentity(request);
}
if (identity == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
// load forum
ICourse course = CoursesWebService.loadCourse(courseId);
if (course == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
} else if (!isAuthorEditor(course, request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
CourseNode courseNode = getParentNode(course, nodeId);
if (courseNode == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
Property forumKeyProp = cpm.findCourseNodeProperty(courseNode, null, null, FOCourseNode.FORUM_KEY);
Forum forum = null;
ForumManager fom = ForumManager.getInstance();
if (forumKeyProp != null) {
// Forum does already exist, load forum with key from properties
Long forumKey = forumKeyProp.getLongValue();
forum = fom.loadForum(forumKey);
}
if (forum == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
MessageVO vo;
if (parentMessageId == null || parentMessageId == 0L) {
// creating the thread (a message without a parent message)
Message newThread = fom.createMessage(forum, identity, false);
if (isSticky != null && isSticky.booleanValue()) {
// set sticky
org.olat.modules.fo.Status status = new org.olat.modules.fo.Status();
status.setSticky(true);
newThread.setStatusCode(org.olat.modules.fo.Status.getStatusCode(status));
}
newThread.setTitle(title);
newThread.setBody(body);
// open a new thread
fom.addTopMessage(newThread);
vo = new MessageVO(newThread);
} else {
// adding response message (a message with a parent message)
Message threadMessage = fom.loadMessage(parentMessageId);
if (threadMessage == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
// create new message
Message message = fom.createMessage(forum, identity, false);
message.setTitle(title);
message.setBody(body);
fom.replyToMessage(message, threadMessage);
vo = new MessageVO(message);
}
return Response.ok(vo).build();
}
use of org.olat.course.properties.CoursePropertyManager in project openolat by klemens.
the class CheckListCourseNode method updateOnPublish.
@Override
public void updateOnPublish(Locale locale, ICourse course, Identity publisher, PublishEvents publishEvents) {
ModuleConfiguration config = getModuleConfiguration();
// sync the checkbox with the database
CheckboxList list = (CheckboxList) config.get(CONFIG_KEY_CHECKBOX);
CheckboxManager checkboxManager = CoreSpringFactory.getImpl(CheckboxManager.class);
checkboxManager.syncCheckbox(list, course, getIdent());
CoursePropertyManager pm = course.getCourseEnvironment().getCoursePropertyManager();
List<Identity> assessedUsers = pm.getAllIdentitiesWithCourseAssessmentData(null);
int count = 0;
for (Identity assessedIdentity : assessedUsers) {
updateScorePassedOnPublish(assessedIdentity, publisher, checkboxManager, course);
if (++count % 10 == 0) {
DBFactory.getInstance().commitAndCloseSession();
}
}
DBFactory.getInstance().commitAndCloseSession();
super.updateOnPublish(locale, course, publisher, publishEvents);
}
use of org.olat.course.properties.CoursePropertyManager in project openolat by klemens.
the class PublishProcess method publishToCatalog.
protected void publishToCatalog(String choiceValue, List<CategoryLabel> labels) {
CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
CourseNode rootNode = course.getRunStructure().getRootNode();
Property prop = cpm.findCourseNodeProperty(rootNode, null, null, "catalog-choice");
if (prop == null) {
prop = cpm.createCourseNodePropertyInstance(rootNode, null, null, "catalog-choice", null, null, choiceValue, null);
cpm.saveProperty(prop);
} else {
prop.setStringValue(choiceValue);
cpm.updateProperty(prop);
}
CatalogManager cm = CoreSpringFactory.getImpl(CatalogManager.class);
List<CatalogEntry> refParentCategories = cm.getCatalogCategoriesFor(repositoryEntry);
a_a: for (CategoryLabel label : labels) {
CatalogEntry category = label.getCategory();
CatalogEntry parentCategory = label.getParentCategory();
if (label.isDeleted()) {
// test
if (category.getKey() != null) {
List<CatalogEntry> children = cm.getChildrenOf(category);
for (CatalogEntry child : children) {
if (child.getRepositoryEntry() != null && child.getRepositoryEntry().equalsByPersistableKey(repositoryEntry)) {
cm.deleteCatalogEntry(child);
}
}
}
} else if (category.getKey() == null) {
// it's a new entry -> check if not already in catalog at this position
for (Iterator<CatalogEntry> refIt = refParentCategories.iterator(); refIt.hasNext(); ) {
CatalogEntry refParentCategory = refIt.next();
if (refParentCategory.equalsByPersistableKey(parentCategory)) {
refIt.remove();
break a_a;
}
}
category.setOwnerGroup(BaseSecurityManager.getInstance().createAndPersistSecurityGroup());
cm.addCatalogEntry(parentCategory, category);
} else {
for (Iterator<CatalogEntry> refIt = refParentCategories.iterator(); refIt.hasNext(); ) {
CatalogEntry refParentCategory = refIt.next();
if (refParentCategory.equalsByPersistableKey(category)) {
refIt.remove();
}
}
}
}
}
use of org.olat.course.properties.CoursePropertyManager in project openolat by klemens.
the class ConvertToGTACourseNode method convertAssessmentDatas.
private void convertAssessmentDatas(TaskList taskList, TACourseNode sourceNode, GTACourseNode gtaNode, ICourse course) {
CourseEnvironment courseEnv = course.getCourseEnvironment();
CoursePropertyManager propertyMgr = courseEnv.getCoursePropertyManager();
Map<Long, AssessmentEntry> datas = new HashMap<>();
List<AssessmentEntry> properties = courseEnv.getAssessmentManager().getAssessmentEntries(sourceNode);
for (AssessmentEntry property : properties) {
Identity identity = property.getIdentity();
datas.put(identity.getKey(), property);
}
properties = null;
DBFactory.getInstance().getCurrentEntityManager().clear();
AssessmentManager assessmentMgr = courseEnv.getAssessmentManager();
for (AssessmentEntry assessmentData : datas.values()) {
Identity assessedIdentity = securityManager.loadIdentityByKey(assessmentData.getIdentity().getKey());
if (assessmentData.getPassed() != null || assessmentData.getScore() != null) {
UserCourseEnvironment userCourseEnv = AssessmentHelper.createAndInitUserCourseEnvironment(assessedIdentity, course);
Float score = assessmentData.getScore() == null ? null : assessmentData.getScore().floatValue();
ScoreEvaluation scoreEval = new ScoreEvaluation(score, assessmentData.getPassed());
assessmentMgr.saveScoreEvaluation(gtaNode, null, assessedIdentity, scoreEval, userCourseEnv, false, Role.auto);
// set graded
Task task = gtaManager.getTask(assessedIdentity, taskList);
if (task == null) {
gtaManager.createTask(null, taskList, TaskProcess.graded, null, assessedIdentity, gtaNode);
} else {
gtaManager.updateTask(task, TaskProcess.graded, gtaNode, Role.auto);
}
}
if (assessmentData.getAttempts() != null) {
assessmentMgr.saveNodeAttempts(gtaNode, null, assessedIdentity, assessmentData.getAttempts().intValue(), Role.auto);
}
if (StringHelper.containsNonWhitespace(assessmentData.getCoachComment())) {
assessmentMgr.saveNodeCoachComment(gtaNode, assessedIdentity, assessmentData.getCoachComment());
}
if (StringHelper.containsNonWhitespace(assessmentData.getComment())) {
assessmentMgr.saveNodeComment(gtaNode, null, assessedIdentity, assessmentData.getComment());
}
}
DBFactory.getInstance().getCurrentEntityManager().clear();
// copy log entries
List<Property> logEntries = propertyMgr.listCourseNodeProperties(sourceNode, null, null, UserNodeAuditManager.LOG_IDENTIFYER);
for (Property logEntry : logEntries) {
String logText = logEntry.getTextValue();
Identity identity = securityManager.loadIdentityByKey(logEntry.getIdentity().getKey());
Property targetProp = propertyMgr.findCourseNodeProperty(gtaNode, identity, null, UserNodeAuditManager.LOG_IDENTIFYER);
if (targetProp == null) {
targetProp = propertyMgr.createCourseNodePropertyInstance(gtaNode, identity, null, UserNodeAuditManager.LOG_IDENTIFYER, null, null, null, logText);
} else {
targetProp.setTextValue(logText);
}
propertyMgr.saveProperty(targetProp);
}
}
Aggregations