Search in sources :

Example 6 with UserEfficiencyStatementImpl

use of org.olat.course.assessment.model.UserEfficiencyStatementImpl in project OpenOLAT by OpenOLAT.

the class EfficiencyStatementManager method updateUserEfficiencyStatement.

public void updateUserEfficiencyStatement(Identity assessedIdentity, final CourseEnvironment courseEnv, List<AssessmentNodeData> assessmentNodeList, AssessmentNodesLastModified lastModifications, final RepositoryEntry repoEntry) {
    List<Map<String, Object>> assessmentNodes = AssessmentHelper.assessmentNodeDataListToMap(assessmentNodeList);
    EfficiencyStatement efficiencyStatement = new EfficiencyStatement();
    efficiencyStatement.setAssessmentNodes(assessmentNodes);
    efficiencyStatement.setCourseTitle(courseEnv.getCourseTitle());
    efficiencyStatement.setCourseRepoEntryKey(repoEntry.getKey());
    String userInfos = userManager.getUserDisplayName(assessedIdentity);
    efficiencyStatement.setDisplayableUserInfo(userInfos);
    efficiencyStatement.setLastUpdated(System.currentTimeMillis());
    if (lastModifications != null) {
        if (lastModifications.getLastUserModified() != null) {
            efficiencyStatement.setLastUserModified(lastModifications.getLastUserModified().getTime());
        }
        if (lastModifications.getLastCoachModified() != null) {
            efficiencyStatement.setLastCoachModified(lastModifications.getLastCoachModified().getTime());
        }
    }
    boolean debug = log.isDebug();
    UserEfficiencyStatementImpl efficiencyProperty = getUserEfficiencyStatementFull(repoEntry, assessedIdentity);
    if (assessmentNodes != null) {
        if (efficiencyProperty == null) {
            // create new
            efficiencyProperty = new UserEfficiencyStatementImpl();
            efficiencyProperty.setIdentity(assessedIdentity);
            efficiencyProperty.setCourseRepoKey(repoEntry.getKey());
            if (repoEntry != null) {
                efficiencyProperty.setResource(repoEntry.getOlatResource());
                efficiencyProperty.setCourseRepoKey(repoEntry.getKey());
            }
            efficiencyProperty.setShortTitle(courseEnv.getRunStructure().getRootNode().getShortTitle());
            efficiencyProperty.setTitle(courseEnv.getRunStructure().getRootNode().getLongTitle());
            fillEfficiencyStatement(efficiencyStatement, lastModifications, efficiencyProperty);
            dbInstance.getCurrentEntityManager().persist(efficiencyProperty);
            if (debug) {
                log.debug("creating new efficiency statement property::" + efficiencyProperty.getKey() + " for id::" + assessedIdentity.getName() + " repoEntry::" + repoEntry.getKey());
            }
        } else {
            // update existing
            if (debug) {
                log.debug("updating efficiency statement property::" + efficiencyProperty.getKey() + " for id::" + assessedIdentity.getName() + " repoEntry::" + repoEntry.getKey());
            }
            efficiencyProperty.setShortTitle(courseEnv.getRunStructure().getRootNode().getShortTitle());
            efficiencyProperty.setTitle(courseEnv.getRunStructure().getRootNode().getLongTitle());
            fillEfficiencyStatement(efficiencyStatement, lastModifications, efficiencyProperty);
            dbInstance.getCurrentEntityManager().merge(efficiencyProperty);
        }
    } else {
        if (efficiencyProperty != null) {
            // remove existing since now empty efficiency statements
            if (debug) {
                log.debug("removing efficiency statement property::" + efficiencyProperty.getKey() + " for id::" + assessedIdentity.getName() + " repoEntry::" + repoEntry.getKey() + " since empty");
            }
            dbInstance.getCurrentEntityManager().remove(efficiencyProperty);
        }
    // else nothing to create and nothing to delete
    }
    // send modified event to everybody
    AssessmentChangedEvent ace = new AssessmentChangedEvent(AssessmentChangedEvent.TYPE_EFFICIENCY_STATEMENT_CHANGED, assessedIdentity);
    OLATResourceable courseOres = OresHelper.createOLATResourceableInstance(CourseModule.class, courseEnv.getCourseResourceableId());
    CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(ace, courseOres);
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) AssessmentChangedEvent(org.olat.course.assessment.AssessmentChangedEvent) UserEfficiencyStatementImpl(org.olat.course.assessment.model.UserEfficiencyStatementImpl) Map(java.util.Map) EfficiencyStatement(org.olat.course.assessment.EfficiencyStatement) UserEfficiencyStatement(org.olat.course.assessment.UserEfficiencyStatement)

Example 7 with UserEfficiencyStatementImpl

use of org.olat.course.assessment.model.UserEfficiencyStatementImpl in project openolat by klemens.

the class OLATUpgrade_8_1_0 method createStatement.

private void createStatement(Property property) {
    String repoKeyStr = property.getName();
    Long repoKey = new Long(repoKeyStr);
    RepositoryEntry re = repositoryManager.lookupRepositoryEntry(repoKey, false);
    UserEfficiencyStatementImpl impl = efficiencyStatementManager.getUserEfficiencyStatementFull(re, property.getIdentity());
    if (impl != null) {
        return;
    }
    UserEfficiencyStatementImpl statement = new UserEfficiencyStatementImpl();
    statement.setIdentity(property.getIdentity());
    statement.setStatementXml(property.getTextValue());
    if (re != null) {
        statement.setResource(re.getOlatResource());
        statement.setCourseRepoKey(re.getKey());
    }
    EfficiencyStatement s = (EfficiencyStatement) XStreamHelper.createXStreamInstance().fromXML(property.getTextValue());
    efficiencyStatementManager.fillEfficiencyStatement(s, null, statement);
    statement.setLastModified(property.getLastModified());
    dbInstance.saveObject(statement);
    dbInstance.commitAndCloseSession();
}
Also used : RepositoryEntry(org.olat.repository.RepositoryEntry) UserEfficiencyStatementImpl(org.olat.course.assessment.model.UserEfficiencyStatementImpl) EfficiencyStatement(org.olat.course.assessment.EfficiencyStatement)

Example 8 with UserEfficiencyStatementImpl

use of org.olat.course.assessment.model.UserEfficiencyStatementImpl in project openolat by klemens.

the class EfficiencyStatementManager method findEfficiencyStatements.

/**
 * Find all efficiency statements for a specific user
 * @param identity
 * @return List of efficiency statements
 */
protected List<EfficiencyStatement> findEfficiencyStatements(Identity identity) {
    List<EfficiencyStatement> efficiencyStatements = new ArrayList<EfficiencyStatement>();
    try {
        StringBuilder sb = new StringBuilder();
        sb.append("select statement from ").append(UserEfficiencyStatementImpl.class.getName()).append(" as statement ").append(" where statement.identity.key=:identityKey");
        List<UserEfficiencyStatementImpl> statements = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), UserEfficiencyStatementImpl.class).setParameter("identityKey", identity.getKey()).getResultList();
        for (UserEfficiencyStatementImpl statement : statements) {
            EfficiencyStatement s = (EfficiencyStatement) xstream.fromXML(statement.getStatementXml());
            efficiencyStatements.add(s);
        }
    } catch (Exception e) {
        log.error("findEfficiencyStatements: " + identity, e);
    }
    return efficiencyStatements;
}
Also used : ArrayList(java.util.ArrayList) UserEfficiencyStatementImpl(org.olat.course.assessment.model.UserEfficiencyStatementImpl) EfficiencyStatement(org.olat.course.assessment.EfficiencyStatement) UserEfficiencyStatement(org.olat.course.assessment.UserEfficiencyStatement)

Example 9 with UserEfficiencyStatementImpl

use of org.olat.course.assessment.model.UserEfficiencyStatementImpl in project openolat by klemens.

the class EfficiencyStatementManager method updateUserEfficiencyStatement.

public void updateUserEfficiencyStatement(Identity assessedIdentity, final CourseEnvironment courseEnv, List<AssessmentNodeData> assessmentNodeList, AssessmentNodesLastModified lastModifications, final RepositoryEntry repoEntry) {
    List<Map<String, Object>> assessmentNodes = AssessmentHelper.assessmentNodeDataListToMap(assessmentNodeList);
    EfficiencyStatement efficiencyStatement = new EfficiencyStatement();
    efficiencyStatement.setAssessmentNodes(assessmentNodes);
    efficiencyStatement.setCourseTitle(courseEnv.getCourseTitle());
    efficiencyStatement.setCourseRepoEntryKey(repoEntry.getKey());
    String userInfos = userManager.getUserDisplayName(assessedIdentity);
    efficiencyStatement.setDisplayableUserInfo(userInfos);
    efficiencyStatement.setLastUpdated(System.currentTimeMillis());
    if (lastModifications != null) {
        if (lastModifications.getLastUserModified() != null) {
            efficiencyStatement.setLastUserModified(lastModifications.getLastUserModified().getTime());
        }
        if (lastModifications.getLastCoachModified() != null) {
            efficiencyStatement.setLastCoachModified(lastModifications.getLastCoachModified().getTime());
        }
    }
    boolean debug = log.isDebug();
    UserEfficiencyStatementImpl efficiencyProperty = getUserEfficiencyStatementFull(repoEntry, assessedIdentity);
    if (assessmentNodes != null) {
        if (efficiencyProperty == null) {
            // create new
            efficiencyProperty = new UserEfficiencyStatementImpl();
            efficiencyProperty.setIdentity(assessedIdentity);
            efficiencyProperty.setCourseRepoKey(repoEntry.getKey());
            if (repoEntry != null) {
                efficiencyProperty.setResource(repoEntry.getOlatResource());
                efficiencyProperty.setCourseRepoKey(repoEntry.getKey());
            }
            efficiencyProperty.setShortTitle(courseEnv.getRunStructure().getRootNode().getShortTitle());
            efficiencyProperty.setTitle(courseEnv.getRunStructure().getRootNode().getLongTitle());
            fillEfficiencyStatement(efficiencyStatement, lastModifications, efficiencyProperty);
            dbInstance.getCurrentEntityManager().persist(efficiencyProperty);
            if (debug) {
                log.debug("creating new efficiency statement property::" + efficiencyProperty.getKey() + " for id::" + assessedIdentity.getName() + " repoEntry::" + repoEntry.getKey());
            }
        } else {
            // update existing
            if (debug) {
                log.debug("updating efficiency statement property::" + efficiencyProperty.getKey() + " for id::" + assessedIdentity.getName() + " repoEntry::" + repoEntry.getKey());
            }
            efficiencyProperty.setShortTitle(courseEnv.getRunStructure().getRootNode().getShortTitle());
            efficiencyProperty.setTitle(courseEnv.getRunStructure().getRootNode().getLongTitle());
            fillEfficiencyStatement(efficiencyStatement, lastModifications, efficiencyProperty);
            dbInstance.getCurrentEntityManager().merge(efficiencyProperty);
        }
    } else {
        if (efficiencyProperty != null) {
            // remove existing since now empty efficiency statements
            if (debug) {
                log.debug("removing efficiency statement property::" + efficiencyProperty.getKey() + " for id::" + assessedIdentity.getName() + " repoEntry::" + repoEntry.getKey() + " since empty");
            }
            dbInstance.getCurrentEntityManager().remove(efficiencyProperty);
        }
    // else nothing to create and nothing to delete
    }
    // send modified event to everybody
    AssessmentChangedEvent ace = new AssessmentChangedEvent(AssessmentChangedEvent.TYPE_EFFICIENCY_STATEMENT_CHANGED, assessedIdentity);
    OLATResourceable courseOres = OresHelper.createOLATResourceableInstance(CourseModule.class, courseEnv.getCourseResourceableId());
    CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(ace, courseOres);
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) AssessmentChangedEvent(org.olat.course.assessment.AssessmentChangedEvent) UserEfficiencyStatementImpl(org.olat.course.assessment.model.UserEfficiencyStatementImpl) Map(java.util.Map) EfficiencyStatement(org.olat.course.assessment.EfficiencyStatement) UserEfficiencyStatement(org.olat.course.assessment.UserEfficiencyStatement)

Example 10 with UserEfficiencyStatementImpl

use of org.olat.course.assessment.model.UserEfficiencyStatementImpl in project openolat by klemens.

the class EfficiencyStatementManager method deleteEfficiencyStatementsFromCourse.

/**
 * Delete all efficiency statements from the given course for all users
 * @param courseRepoEntryKey
 * @return int number of deleted efficiency statements
 */
public void deleteEfficiencyStatementsFromCourse(Long courseRepoEntryKey) {
    try {
        StringBuilder sb = new StringBuilder();
        sb.append("select statement from ").append(UserEfficiencyStatementImpl.class.getName()).append(" as statement ").append(" where statement.courseRepoKey=:repoKey");
        List<UserEfficiencyStatementImpl> statements = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), UserEfficiencyStatementImpl.class).setParameter("repoKey", courseRepoEntryKey).getResultList();
        for (UserEfficiencyStatementImpl statement : statements) {
            dbInstance.deleteObject(statement);
        }
    } catch (Exception e) {
        log.error("deleteEfficiencyStatementsFromCourse: " + courseRepoEntryKey, e);
    }
}
Also used : UserEfficiencyStatementImpl(org.olat.course.assessment.model.UserEfficiencyStatementImpl)

Aggregations

UserEfficiencyStatementImpl (org.olat.course.assessment.model.UserEfficiencyStatementImpl)10 EfficiencyStatement (org.olat.course.assessment.EfficiencyStatement)6 UserEfficiencyStatement (org.olat.course.assessment.UserEfficiencyStatement)4 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Map (java.util.Map)2 OLATResourceable (org.olat.core.id.OLATResourceable)2 ICourse (org.olat.course.ICourse)2 AssessmentChangedEvent (org.olat.course.assessment.AssessmentChangedEvent)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2