CourseConfig cc = userCourseEnv.getCourseEnvironment().getCourseConfig();
// write only when enabled for this course
if (cc.isEfficencyStatementEnabled()) {
final boolean logDebug = log.isDebug();
final Identity identity = userCourseEnv.getIdentityEnvironment().getIdentity();
final PropertyManager pm = PropertyManager.getInstance();
final String courseRepoEntryKey = getPropertyName(repoEntryKey);
CourseNode rootNode = userCourseEnv.getCourseEnvironment().getRunStructure().getRootNode();
List<Map<String,Object>> assessmentNodes = AssessmentHelper.addAssessableNodeAndDataToList(0, rootNode, userCourseEnv, true, true);
EfficiencyStatement efficiencyStatement = new EfficiencyStatement();
efficiencyStatement.setAssessmentNodes(assessmentNodes);
efficiencyStatement.setCourseTitle(userCourseEnv.getCourseEnvironment().getCourseTitle());
efficiencyStatement.setCourseRepoEntryKey(repoEntryKey);
User user = identity.getUser();
efficiencyStatement.setDisplayableUserInfo(user.getProperty(UserConstants.FIRSTNAME, null) + " " + user.getProperty(UserConstants.LASTNAME, null) + " (" + identity.getName() + ")");
efficiencyStatement.setLastUpdated(System.currentTimeMillis());
// save efficiency statement as xtream persisted list
final String efficiencyStatementX = XStreamHelper.toXML(efficiencyStatement);
Property efficiencyProperty = null;
if (checkForExistingProperty) {
efficiencyProperty = pm.findUserProperty(identity, PROPERTY_CATEGORY, courseRepoEntryKey);
}
if (assessmentNodes != null) {
if (efficiencyProperty == null) {
// create new
efficiencyProperty = pm.createUserPropertyInstance(identity, PROPERTY_CATEGORY, courseRepoEntryKey, null, null, null, efficiencyStatementX);
pm.saveProperty(efficiencyProperty);
if (logDebug) log.debug("creating new efficiency statement property::" + efficiencyProperty.getKey() + " for id::"
+ identity.getName() + " repoEntry::" + courseRepoEntryKey);
} else {
// update existing
if (logDebug) log.debug("updatting efficiency statement property::" + efficiencyProperty.getKey() + " for id::"
+ identity.getName() + " repoEntry::" + courseRepoEntryKey);
efficiencyProperty.setTextValue(efficiencyStatementX);
pm.updateProperty(efficiencyProperty);
}
} else {
if (efficiencyProperty != null) {
// remove existing since now empty empty efficiency statements
if (logDebug) log.debug("removing efficiency statement property::" + efficiencyProperty.getKey() + " for id::"
+ identity.getName() + " repoEntry::" + courseRepoEntryKey + " since empty");
pm.deleteProperty(efficiencyProperty);
}
// else nothing to create and nothing to delete
}
// send modified event to everybody