Search in sources :

Example 1 with NewCacheKey

use of org.olat.upgrade.legacy.NewCacheKey in project OpenOLAT by OpenOLAT.

the class OLATUpgrade_11_0_0 method verifyCourseAssessmentData.

/**
 * The method compare the content of the cache used in assessment tool
 * with the migrated values and vice versa.
 *
 * @param courseEntry
 * @return
 */
private boolean verifyCourseAssessmentData(List<Identity> assessableIdentities, RepositoryEntry courseEntry) {
    // load the cache and fill it with the same amount of datas as in assessment tool
    final ICourse course = CourseFactory.loadCourse(courseEntry);
    final Long courseResourceableId = course.getResourceableId();
    StaticCacheWrapper cache = new StaticCacheWrapper();
    NewCachePersistingAssessmentManager assessmentManager = new NewCachePersistingAssessmentManager(course, cache);
    assessmentManager.preloadCache(assessableIdentities);
    dbInstance.commitAndCloseSession();
    Set<Identity> assessableIdentitySet = new HashSet<>(assessableIdentities);
    List<AssessmentEntryImpl> nodeAssessments = loadAssessmentEntries(courseEntry);
    Map<AssessmentDataKey, AssessmentEntryImpl> nodeAssessmentMap = new HashMap<>();
    for (AssessmentEntryImpl nodeAssessment : nodeAssessments) {
        if (!assessableIdentitySet.contains(nodeAssessment.getIdentity())) {
            assessmentManager.preloadCache(nodeAssessment.getIdentity());
        }
        if (nodeAssessment.getIdentity() != null && nodeAssessment.getRepositoryEntry() != null && nodeAssessment.getRepositoryEntry().getOlatResource() != null) {
            nodeAssessmentMap.put(new AssessmentDataKey(nodeAssessment), nodeAssessment);
        }
    }
    dbInstance.commitAndCloseSession();
    // compare the value in CourseNodeAssessment with the content of the cache
    boolean allOk = true;
    for (AssessmentEntryImpl nodeAssessment : nodeAssessments) {
        allOk &= compareCourseNodeAssessment(nodeAssessment, assessmentManager, course, courseEntry);
    }
    dbInstance.commitAndCloseSession();
    // compare the content of the cache with the CourseNodeAssessments
    for (NewCacheKey cacheKey : cache.getKeys()) {
        Map<String, Serializable> dataMap = cache.get(cacheKey);
        Long identityKey = cacheKey.getIdentityKey();
        for (Map.Entry<String, Serializable> data : dataMap.entrySet()) {
            String key = data.getKey();
            int index = key.indexOf("_");
            if (index > 0 && !key.equals("LAST_MODIFIED")) {
                String nodeIdent = key.substring(0, index);
                String dataType = key.substring(index + 1);
                AssessmentDataKey assessmentDataKey = new AssessmentDataKey(identityKey, courseResourceableId, nodeIdent);
                AssessmentEntryImpl nodeAssessment = nodeAssessmentMap.get(assessmentDataKey);
                allOk &= compareProperty(dataType, data.getValue(), nodeAssessment, courseEntry, nodeIdent, identityKey);
            }
        }
    }
    dbInstance.commitAndCloseSession();
    if (!allOk) {
        log.error("Critical error during course verification: " + courseEntry.getDisplayname() + "(" + courseEntry.getKey() + ")");
    }
    return allOk;
}
Also used : Serializable(java.io.Serializable) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) NewCacheKey(org.olat.upgrade.legacy.NewCacheKey) NewCachePersistingAssessmentManager(org.olat.upgrade.legacy.NewCachePersistingAssessmentManager) ICourse(org.olat.course.ICourse) AssessmentEntryImpl(org.olat.modules.assessment.model.AssessmentEntryImpl) Identity(org.olat.core.id.Identity) TransientIdentity(org.olat.admin.user.imp.TransientIdentity) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) PortfolioStructureMap(org.olat.portfolio.model.structel.PortfolioStructureMap) HashSet(java.util.HashSet)

Example 2 with NewCacheKey

use of org.olat.upgrade.legacy.NewCacheKey in project openolat by klemens.

the class OLATUpgrade_11_0_0 method verifyCourseAssessmentData.

/**
 * The method compare the content of the cache used in assessment tool
 * with the migrated values and vice versa.
 *
 * @param courseEntry
 * @return
 */
private boolean verifyCourseAssessmentData(List<Identity> assessableIdentities, RepositoryEntry courseEntry) {
    // load the cache and fill it with the same amount of datas as in assessment tool
    final ICourse course = CourseFactory.loadCourse(courseEntry);
    final Long courseResourceableId = course.getResourceableId();
    StaticCacheWrapper cache = new StaticCacheWrapper();
    NewCachePersistingAssessmentManager assessmentManager = new NewCachePersistingAssessmentManager(course, cache);
    assessmentManager.preloadCache(assessableIdentities);
    dbInstance.commitAndCloseSession();
    Set<Identity> assessableIdentitySet = new HashSet<>(assessableIdentities);
    List<AssessmentEntryImpl> nodeAssessments = loadAssessmentEntries(courseEntry);
    Map<AssessmentDataKey, AssessmentEntryImpl> nodeAssessmentMap = new HashMap<>();
    for (AssessmentEntryImpl nodeAssessment : nodeAssessments) {
        if (!assessableIdentitySet.contains(nodeAssessment.getIdentity())) {
            assessmentManager.preloadCache(nodeAssessment.getIdentity());
        }
        if (nodeAssessment.getIdentity() != null && nodeAssessment.getRepositoryEntry() != null && nodeAssessment.getRepositoryEntry().getOlatResource() != null) {
            nodeAssessmentMap.put(new AssessmentDataKey(nodeAssessment), nodeAssessment);
        }
    }
    dbInstance.commitAndCloseSession();
    // compare the value in CourseNodeAssessment with the content of the cache
    boolean allOk = true;
    for (AssessmentEntryImpl nodeAssessment : nodeAssessments) {
        allOk &= compareCourseNodeAssessment(nodeAssessment, assessmentManager, course, courseEntry);
    }
    dbInstance.commitAndCloseSession();
    // compare the content of the cache with the CourseNodeAssessments
    for (NewCacheKey cacheKey : cache.getKeys()) {
        Map<String, Serializable> dataMap = cache.get(cacheKey);
        Long identityKey = cacheKey.getIdentityKey();
        for (Map.Entry<String, Serializable> data : dataMap.entrySet()) {
            String key = data.getKey();
            int index = key.indexOf("_");
            if (index > 0 && !key.equals("LAST_MODIFIED")) {
                String nodeIdent = key.substring(0, index);
                String dataType = key.substring(index + 1);
                AssessmentDataKey assessmentDataKey = new AssessmentDataKey(identityKey, courseResourceableId, nodeIdent);
                AssessmentEntryImpl nodeAssessment = nodeAssessmentMap.get(assessmentDataKey);
                allOk &= compareProperty(dataType, data.getValue(), nodeAssessment, courseEntry, nodeIdent, identityKey);
            }
        }
    }
    dbInstance.commitAndCloseSession();
    if (!allOk) {
        log.error("Critical error during course verification: " + courseEntry.getDisplayname() + "(" + courseEntry.getKey() + ")");
    }
    return allOk;
}
Also used : Serializable(java.io.Serializable) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) NewCacheKey(org.olat.upgrade.legacy.NewCacheKey) NewCachePersistingAssessmentManager(org.olat.upgrade.legacy.NewCachePersistingAssessmentManager) ICourse(org.olat.course.ICourse) AssessmentEntryImpl(org.olat.modules.assessment.model.AssessmentEntryImpl) Identity(org.olat.core.id.Identity) TransientIdentity(org.olat.admin.user.imp.TransientIdentity) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) PortfolioStructureMap(org.olat.portfolio.model.structel.PortfolioStructureMap) HashSet(java.util.HashSet)

Aggregations

Serializable (java.io.Serializable)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 TransientIdentity (org.olat.admin.user.imp.TransientIdentity)2 Identity (org.olat.core.id.Identity)2 ICourse (org.olat.course.ICourse)2 AssessmentEntryImpl (org.olat.modules.assessment.model.AssessmentEntryImpl)2 PortfolioStructureMap (org.olat.portfolio.model.structel.PortfolioStructureMap)2 NewCacheKey (org.olat.upgrade.legacy.NewCacheKey)2 NewCachePersistingAssessmentManager (org.olat.upgrade.legacy.NewCachePersistingAssessmentManager)2