Search in sources :

Example 1 with CoursePropertyManager

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;
}
Also used : ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) Property(org.olat.properties.Property) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager) PersistingCoursePropertyManager(org.olat.course.properties.PersistingCoursePropertyManager)

Example 2 with CoursePropertyManager

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);
    }
}
Also used : ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) Task(org.olat.course.nodes.gta.Task) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) HashMap(java.util.HashMap) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) AssessmentManager(org.olat.course.assessment.AssessmentManager) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) Identity(org.olat.core.id.Identity) Property(org.olat.properties.Property) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager)

Example 3 with CoursePropertyManager

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);
    }
}
Also used : Property(org.olat.properties.Property) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager)

Example 4 with CoursePropertyManager

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);
    }
}
Also used : Identity(org.olat.core.id.Identity) Property(org.olat.properties.Property) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager)

Example 5 with CoursePropertyManager

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...");
}
Also used : ENCourseNode(org.olat.course.nodes.ENCourseNode) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager) Test(org.junit.Test)

Aggregations

CoursePropertyManager (org.olat.course.properties.CoursePropertyManager)108 Property (org.olat.properties.Property)62 PersistingCoursePropertyManager (org.olat.course.properties.PersistingCoursePropertyManager)44 Identity (org.olat.core.id.Identity)28 File (java.io.File)18 ICourse (org.olat.course.ICourse)18 ProjectBrokerManager (org.olat.course.nodes.projectbroker.service.ProjectBrokerManager)14 CourseNode (org.olat.course.nodes.CourseNode)12 Project (org.olat.course.nodes.projectbroker.datamodel.Project)12 RepositoryEntry (org.olat.repository.RepositoryEntry)12 AssessmentChangedEvent (org.olat.course.assessment.AssessmentChangedEvent)10 UserNodeAuditManager (org.olat.course.auditing.UserNodeAuditManager)10 ProjectGroupManager (org.olat.course.nodes.projectbroker.service.ProjectGroupManager)10 BusinessGroup (org.olat.group.BusinessGroup)10 XStream (com.thoughtworks.xstream.XStream)8 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)8 TaskExecutorManager (org.olat.core.commons.services.taskexecutor.TaskExecutorManager)8 PackageTranslator (org.olat.core.gui.translator.PackageTranslator)8 Translator (org.olat.core.gui.translator.Translator)8 SyncerExecutor (org.olat.core.util.coordinate.SyncerExecutor)8