Search in sources :

Example 96 with Property

use of org.olat.properties.Property in project openolat by klemens.

the class NewCachePersistingAssessmentManager method preloadCache.

public void preloadCache(List<Identity> identities) {
    int count = 0;
    int batch = 200;
    Map<Identity, List<Property>> map = new HashMap<Identity, List<Property>>(201);
    do {
        int toIndex = Math.min(count + batch, identities.size());
        List<Identity> toLoad = identities.subList(count, toIndex);
        List<Property> allProperties = loadPropertiesFor(toLoad);
        map.clear();
        for (Property prop : allProperties) {
            if (!map.containsKey(prop.getIdentity())) {
                map.put(prop.getIdentity(), new ArrayList<Property>());
            }
            map.get(prop.getIdentity()).add(prop);
        }
        for (Identity id : toLoad) {
            List<Property> props = map.get(id);
            if (props == null) {
                props = new ArrayList<Property>(1);
            }
            getOrLoadScorePassedAttemptsMap(id, props, false);
        }
        count += batch;
    } while (count < identities.size());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) Identity(org.olat.core.id.Identity) Property(org.olat.properties.Property)

Example 97 with Property

use of org.olat.properties.Property in project openolat by klemens.

the class NewCachePersistingAssessmentManager method incrementNodeAttemptsProperty.

/**
 * Private method. Increments the attempts property.
 * @param courseNode
 * @param identity
 * @param cpm
 * @return the resulting new number of node attempts
 */
private long incrementNodeAttemptsProperty(CourseNode courseNode, Identity identity, CoursePropertyManager cpm) {
    Long attempts;
    Property attemptsProperty = cpm.findCourseNodeProperty(courseNode, identity, null, ATTEMPTS);
    if (attemptsProperty == null) {
        attempts = new Long(1);
        attemptsProperty = cpm.createCourseNodePropertyInstance(courseNode, identity, null, ATTEMPTS, null, attempts, null, null);
        cpm.saveProperty(attemptsProperty);
    } else {
        attempts = new Long(attemptsProperty.getLongValue().longValue() + 1);
        attemptsProperty.setLongValue(attempts);
        cpm.updateProperty(attemptsProperty);
    }
    // add to cache
    putPropertyIntoCache(identity, attemptsProperty);
    return attempts;
}
Also used : Property(org.olat.properties.Property)

Example 98 with Property

use of org.olat.properties.Property in project openolat by klemens.

the class NewCachePersistingAssessmentManager method saveAssessmentID.

/**
 * @param courseNode
 * @param assessedIdentity
 * @param assessmentID
 * @param coursePropManager
 */
void saveAssessmentID(CourseNode courseNode, Identity assessedIdentity, Long assessmentID, CoursePropertyManager coursePropManager) {
    if (assessmentID != null) {
        Property assessmentIDProperty = coursePropManager.findCourseNodeProperty(courseNode, assessedIdentity, null, ASSESSMENT_ID);
        if (assessmentIDProperty == null) {
            assessmentIDProperty = coursePropManager.createCourseNodePropertyInstance(courseNode, assessedIdentity, null, ASSESSMENT_ID, null, assessmentID, null, null);
            coursePropManager.saveProperty(assessmentIDProperty);
        } else {
            assessmentIDProperty.setLongValue(assessmentID);
            coursePropManager.updateProperty(assessmentIDProperty);
        }
        // add to cache
        putPropertyIntoCache(assessedIdentity, assessmentIDProperty);
    }
}
Also used : Property(org.olat.properties.Property)

Example 99 with Property

use of org.olat.properties.Property in project openolat by klemens.

the class NewCachePersistingAssessmentManager method saveNodePassed.

/**
 * @param courseNode
 * @param identity
 * @param assessedIdentity
 * @param passed
 * @param coursePropManager
 */
void saveNodePassed(CourseNode courseNode, Identity assessedIdentity, Boolean passed, CoursePropertyManager coursePropManager) {
    Property passedProperty = coursePropManager.findCourseNodeProperty(courseNode, assessedIdentity, null, PASSED);
    if (passedProperty == null && passed != null) {
        String pass = passed.toString();
        passedProperty = coursePropManager.createCourseNodePropertyInstance(courseNode, assessedIdentity, null, PASSED, null, null, pass, null);
        coursePropManager.saveProperty(passedProperty);
    } else if (passedProperty != null) {
        if (passed != null) {
            passedProperty.setStringValue(passed.toString());
            coursePropManager.updateProperty(passedProperty);
        } else {
            removePropertyFromCache(assessedIdentity, passedProperty);
            coursePropManager.deleteProperty(passedProperty);
        }
    }
    // add to cache
    if (passed != null && passedProperty != null) {
        putPropertyIntoCache(assessedIdentity, passedProperty);
    }
}
Also used : Property(org.olat.properties.Property)

Example 100 with Property

use of org.olat.properties.Property in project openolat by klemens.

the class NewCachePersistingAssessmentManager method saveNodeCoachComment.

/**
 * @see org.olat.course.assessment.AssessmentManager#saveNodeCoachComment(org.olat.course.nodes.CourseNode,
 *      org.olat.core.id.Identity, java.lang.String)
 */
public void saveNodeCoachComment(final CourseNode courseNode, final Identity assessedIdentity, final String comment) {
    ICourse course = CourseFactory.loadCourse(ores);
    final CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
    CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(createOLATResourceableForLocking(assessedIdentity), new SyncerExecutor() {

        public void execute() {
            Property commentProperty = cpm.findCourseNodeProperty(courseNode, assessedIdentity, null, COACH_COMMENT);
            if (commentProperty == null) {
                commentProperty = cpm.createCourseNodePropertyInstance(courseNode, assessedIdentity, null, COACH_COMMENT, null, null, null, comment);
                cpm.saveProperty(commentProperty);
            } else {
                commentProperty.setTextValue(comment);
                cpm.updateProperty(commentProperty);
            }
            // add to cache
            putPropertyIntoCache(assessedIdentity, commentProperty);
        }
    });
    // olat::: no node log here? (because what we did above is a node log with custom text AND by a coach)?
    // notify about changes
    AssessmentChangedEvent ace = new AssessmentChangedEvent(AssessmentChangedEvent.TYPE_COACH_COMMENT_CHANGED, assessedIdentity);
    CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(ace, course);
    // user activity logging
    ThreadLocalUserActivityLogger.log(AssessmentLoggingAction.ASSESSMENT_COACHCOMMENT_UPDATED, getClass(), LoggingResourceable.wrap(assessedIdentity), LoggingResourceable.wrapNonOlatResource(StringResourceableType.qtiCoachComment, "", StringHelper.stripLineBreaks(comment)));
}
Also used : AssessmentChangedEvent(org.olat.course.assessment.AssessmentChangedEvent) ICourse(org.olat.course.ICourse) SyncerExecutor(org.olat.core.util.coordinate.SyncerExecutor) Property(org.olat.properties.Property) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager)

Aggregations

Property (org.olat.properties.Property)270 CoursePropertyManager (org.olat.course.properties.CoursePropertyManager)62 PropertyManager (org.olat.properties.PropertyManager)48 Identity (org.olat.core.id.Identity)36 NarrowedPropertyManager (org.olat.properties.NarrowedPropertyManager)36 ArrayList (java.util.ArrayList)24 PersistingCoursePropertyManager (org.olat.course.properties.PersistingCoursePropertyManager)22 BusinessGroup (org.olat.group.BusinessGroup)18 File (java.io.File)16 ICourse (org.olat.course.ICourse)16 Translator (org.olat.core.gui.translator.Translator)14 AssertException (org.olat.core.logging.AssertException)14 CourseNode (org.olat.course.nodes.CourseNode)14 Forum (org.olat.modules.fo.Forum)14 ForumManager (org.olat.modules.fo.manager.ForumManager)14 Test (org.junit.Test)12 SyncerExecutor (org.olat.core.util.coordinate.SyncerExecutor)12 XStream (com.thoughtworks.xstream.XStream)10 HashMap (java.util.HashMap)10 List (java.util.List)10