use of org.olat.course.properties.CoursePropertyManager in project OpenOLAT by OpenOLAT.
the class TaskFolderCallback method removeAssignedTask.
/**
* Cancel the task assignment for this task and all Identities.
* @param course
* @param task
* @return Returns the Identities list that have had this task assigned.
*/
private List<Identity> removeAssignedTask(ICourse course, String task) {
// identities to be notified
List<Identity> identityList = new ArrayList<Identity>();
CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
List<Property> properties = cpm.listCourseNodeProperties(node, null, null, TaskController.PROP_ASSIGNED);
if (properties != null && properties.size() > 0) {
for (Object propetyObj : properties) {
Property propety = (Property) propetyObj;
identityList.add(propety.getIdentity());
cpm.deleteProperty(propety);
}
}
return identityList;
}
use of org.olat.course.properties.CoursePropertyManager in project OpenOLAT by OpenOLAT.
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);
}
}
use of org.olat.course.properties.CoursePropertyManager in project OpenOLAT by OpenOLAT.
the class ReturnboxFullAccessCallback method removeAssignedTask.
/**
* Cancel the task assignment.
* @param identity
* @param task
*/
private void removeAssignedTask(UserCourseEnvironment courseEnv, Identity identity) {
CoursePropertyManager cpm = courseEnv.getCourseEnvironment().getCoursePropertyManager();
List<Property> properties = cpm.findCourseNodeProperties(node, identity, null, TaskController.PROP_ASSIGNED);
if (properties != null && properties.size() > 0) {
Property propety = properties.get(0);
cpm.deleteProperty(propety);
assignedTask = null;
}
// removed sampled
properties = cpm.findCourseNodeProperties(node, null, null, TaskController.PROP_SAMPLED);
if (properties != null && properties.size() > 0) {
Property propety = properties.get(0);
cpm.deleteProperty(propety);
}
}
use of org.olat.course.properties.CoursePropertyManager in project OpenOLAT by OpenOLAT.
the class StatusManager method saveStatusFormData.
public void saveStatusFormData(StatusForm statusForm, CourseNode node, UserCourseEnvironment userCourseEnv) {
Identity identity = userCourseEnv.getIdentityEnvironment().getIdentity();
String selectedKey = statusForm.getSelectedStatus();
CoursePropertyManager cpm = userCourseEnv.getCourseEnvironment().getCoursePropertyManager();
Property statusProperty;
statusProperty = cpm.findCourseNodeProperty(node, identity, null, PROPERTY_KEY_STATUS);
if (statusProperty == null) {
statusProperty = cpm.createCourseNodePropertyInstance(node, identity, null, PROPERTY_KEY_STATUS, null, null, selectedKey, null);
cpm.saveProperty(statusProperty);
} else {
statusProperty.setStringValue(selectedKey);
cpm.updateProperty(statusProperty);
}
}
use of org.olat.course.properties.CoursePropertyManager in project OpenOLAT by OpenOLAT.
the class EnrollmentManagerConcurrentTest method testEnroll.
// Test for WaitingList
// /////////////////////
/**
* Enroll 3 identities (group with max-size=2 and waiting-list).
* Cancel enrollment. Check size after each step.
*/
@Test
public void testEnroll() throws Exception {
log.info("testEnroll: start...");
ENCourseNode enNode = new ENCourseNode();
OLATResource resource = resourceManager.createOLATResourceInstance(CourseModule.class);
RepositoryEntry addedEntry = repositoryService.create("Ayanami", "-", "Enrollment test course 1", "A JUnit course", resource);
CourseEnvironment cenv = CourseFactory.createCourse(addedEntry, "Test", "Test", "learningObjectives").getCourseEnvironment();
// 1. enroll wg1 user
IdentityEnvironment ienv = new IdentityEnvironment();
ienv.setIdentity(wg1);
UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(ienv, cenv);
CoursePropertyManager coursePropertyManager = userCourseEnv.getCourseEnvironment().getCoursePropertyManager();
log.info("enrollmentManager=" + enrollmentManager);
log.info("bgWithWaitingList=" + bgWithWaitingList);
assertTrue("bgWithWaitingList is null", bgWithWaitingList != null);
log.info("userCourseEnv=" + userCourseEnv);
log.info("userCourseEnv.getCourseEnvironment()=" + userCourseEnv.getCourseEnvironment());
enrollmentManager.doEnroll(wg1, wg1Roles, bgWithWaitingList, enNode, coursePropertyManager, this, /*WindowControl mock*/
testTranslator, new ArrayList<Long>(), /*enrollableGroupNames*/
new ArrayList<Long>(), /*enrollableAreaNames*/
userCourseEnv.getCourseEnvironment().getCourseGroupManager());
assertTrue("Enrollment failed, user='wg1'", businessGroupService.isIdentityInBusinessGroup(wg1, bgWithWaitingList));
int participantsCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.participant.name());
assertTrue("Wrong number of participants," + participantsCounter, participantsCounter == 1);
// 2. enroll wg2 user
ienv = new IdentityEnvironment();
ienv.setIdentity(wg2);
userCourseEnv = new UserCourseEnvironmentImpl(ienv, cenv);
coursePropertyManager = userCourseEnv.getCourseEnvironment().getCoursePropertyManager();
enrollmentManager.doEnroll(wg2, wg2Roles, bgWithWaitingList, enNode, coursePropertyManager, this, /*WindowControl mock*/
testTranslator, new ArrayList<Long>(), /*enrollableGroupNames*/
new ArrayList<Long>(), /*enrollableAreaNames*/
userCourseEnv.getCourseEnvironment().getCourseGroupManager());
assertTrue("Enrollment failed, user='wg2'", businessGroupService.isIdentityInBusinessGroup(wg2, bgWithWaitingList));
assertTrue("Enrollment failed, user='wg1'", businessGroupService.isIdentityInBusinessGroup(wg1, bgWithWaitingList));
participantsCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.participant.name());
assertTrue("Wrong number of participants," + participantsCounter, participantsCounter == 2);
// 3. enroll wg3 user => list is full => waiting-list
ienv = new IdentityEnvironment();
ienv.setIdentity(wg3);
userCourseEnv = new UserCourseEnvironmentImpl(ienv, cenv);
coursePropertyManager = userCourseEnv.getCourseEnvironment().getCoursePropertyManager();
enrollmentManager.doEnroll(wg3, wg3Roles, bgWithWaitingList, enNode, coursePropertyManager, this, /*WindowControl mock*/
testTranslator, new ArrayList<Long>(), /*enrollableGroupNames*/
new ArrayList<Long>(), /*enrollableAreaNames*/
userCourseEnv.getCourseEnvironment().getCourseGroupManager());
assertFalse("Wrong enrollment, user='wg3' is in PartipiciantGroup, must be on waiting-list", businessGroupService.isIdentityInBusinessGroup(wg3, bgWithWaitingList));
assertFalse("Wrong enrollment, user='wg3' is in PartipiciantGroup, must be on waiting-list", businessGroupService.hasRoles(wg3, bgWithWaitingList, GroupRoles.participant.name()));
assertTrue("Wrong enrollment, user='wg3' must be on waiting-list", businessGroupService.hasRoles(wg3, bgWithWaitingList, GroupRoles.waiting.name()));
assertTrue("Enrollment failed, user='wg2'", businessGroupService.isIdentityInBusinessGroup(wg2, bgWithWaitingList));
assertTrue("Enrollment failed, user='wg1'", businessGroupService.isIdentityInBusinessGroup(wg1, bgWithWaitingList));
participantsCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.participant.name());
assertTrue("Wrong number of participants," + participantsCounter, participantsCounter == 2);
int waitingListCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.waiting.name());
assertTrue("Wrong number of waiting-list, must be 1, is " + waitingListCounter, waitingListCounter == 1);
// cancel enrollment for wg2 => transfer wg3 from waiting-list to participants
ienv = new IdentityEnvironment();
ienv.setIdentity(wg2);
userCourseEnv = new UserCourseEnvironmentImpl(ienv, cenv);
coursePropertyManager = userCourseEnv.getCourseEnvironment().getCoursePropertyManager();
enrollmentManager.doCancelEnrollment(wg2, bgWithWaitingList, enNode, coursePropertyManager, this, /*WindowControl mock*/
testTranslator);
assertFalse("Cancel enrollment failed, user='wg2' is still participants.", businessGroupService.isIdentityInBusinessGroup(wg2, bgWithWaitingList));
assertTrue("Enrollment failed, user='wg3'", businessGroupService.isIdentityInBusinessGroup(wg3, bgWithWaitingList));
assertTrue("Enrollment failed, user='wg1'", businessGroupService.isIdentityInBusinessGroup(wg1, bgWithWaitingList));
participantsCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.participant.name());
assertTrue("Wrong number of participants, must be 2, is " + participantsCounter, participantsCounter == 2);
waitingListCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.waiting.name());
assertTrue("Wrong number of waiting-list, must be 0, is " + waitingListCounter, waitingListCounter == 0);
// cancel enrollment for wg1
ienv = new IdentityEnvironment();
ienv.setIdentity(wg1);
userCourseEnv = new UserCourseEnvironmentImpl(ienv, cenv);
coursePropertyManager = userCourseEnv.getCourseEnvironment().getCoursePropertyManager();
enrollmentManager.doCancelEnrollment(wg1, bgWithWaitingList, enNode, coursePropertyManager, this, /*WindowControl mock*/
testTranslator);
assertFalse("Cancel enrollment failed, user='wg2' is still participants.", businessGroupService.isIdentityInBusinessGroup(wg2, bgWithWaitingList));
assertFalse("Cancel enrollment failed, user='wg1' is still participants.", businessGroupService.isIdentityInBusinessGroup(wg1, bgWithWaitingList));
assertTrue("Enrollment failed, user='wg3'", businessGroupService.isIdentityInBusinessGroup(wg3, bgWithWaitingList));
participantsCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.participant.name());
assertTrue("Wrong number of participants, must be 1, is " + participantsCounter, participantsCounter == 1);
waitingListCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.waiting.name());
assertTrue("Wrong number of waiting-list, must be 0, is " + waitingListCounter, waitingListCounter == 0);
// cancel enrollment for wg3
ienv = new IdentityEnvironment();
ienv.setIdentity(wg3);
userCourseEnv = new UserCourseEnvironmentImpl(ienv, cenv);
coursePropertyManager = userCourseEnv.getCourseEnvironment().getCoursePropertyManager();
enrollmentManager.doCancelEnrollment(wg3, bgWithWaitingList, enNode, coursePropertyManager, this, /*WindowControl mock*/
testTranslator);
assertFalse("Cancel enrollment failed, user='wg3' is still participants.", businessGroupService.isIdentityInBusinessGroup(wg3, bgWithWaitingList));
assertFalse("Cancel enrollment failed, user='wg2' is still participants.", businessGroupService.isIdentityInBusinessGroup(wg2, bgWithWaitingList));
assertFalse("Cancel enrollment failed, user='wg1' is still participants.", businessGroupService.isIdentityInBusinessGroup(wg1, bgWithWaitingList));
participantsCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.participant.name());
assertTrue("Wrong number of participants, must be 0, is " + participantsCounter, participantsCounter == 0);
waitingListCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.waiting.name());
assertTrue("Wrong number of waiting-list, must be 0, is " + waitingListCounter, waitingListCounter == 0);
log.info("testEnroll: done...");
}
Aggregations