use of org.olat.core.util.event.EventBus in project openolat by klemens.
the class CertificatesOptionsController method doChangeConfig.
private void doChangeConfig(UserRequest ureq) {
OLATResourceable courseOres = entry.getOlatResource();
if (CourseFactory.isCourseEditSessionOpen(courseOres.getResourceableId())) {
showWarning("error.editoralreadylocked", new String[] { "???" });
return;
}
ICourse course = CourseFactory.openCourseEditSession(courseOres.getResourceableId());
courseConfig = course.getCourseEnvironment().getCourseConfig();
boolean enableEfficiencyStatment = efficencyEl.isSelected(0);
boolean updateStatement = courseConfig.isEfficencyStatementEnabled() != enableEfficiencyStatment;
courseConfig.setEfficencyStatementIsEnabled(enableEfficiencyStatment);
Collection<String> certificationOptions = pdfCertificatesEl.getSelectedKeys();
courseConfig.setAutomaticCertificationEnabled(certificationOptions.contains(PDFCertificatesOptions.auto.name()));
courseConfig.setManualCertificationEnabled(certificationOptions.contains(PDFCertificatesOptions.manual.name()));
if (selectedTemplate != null) {
Long templateId = selectedTemplate.getKey();
courseConfig.setCertificateTemplate(templateId);
} else {
courseConfig.setCertificateTemplate(null);
}
boolean recertificationEnabled = reCertificationEl.isEnabled() && reCertificationEl.isAtLeastSelected(1);
courseConfig.setRecertificationEnabled(recertificationEnabled);
if (recertificationEnabled) {
int timelapse = reCertificationTimelapseEl.getIntValue();
courseConfig.setRecertificationTimelapse(timelapse);
if (reCertificationTimelapseUnitEl.isOneSelected()) {
String selectedUnit = reCertificationTimelapseUnitEl.getSelectedKey();
RecertificationTimeUnit timeUnit = RecertificationTimeUnit.valueOf(selectedUnit);
courseConfig.setRecertificationTimelapseUnit(timeUnit);
} else {
courseConfig.setRecertificationTimelapseUnit(RecertificationTimeUnit.month);
}
} else {
courseConfig.setRecertificationTimelapse(0);
courseConfig.setRecertificationTimelapseUnit(null);
}
CourseFactory.setCourseConfig(course.getResourceableId(), courseConfig);
CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
if (updateStatement) {
if (enableEfficiencyStatment) {
// first create the efficiencies, send event to agency (all courses add link)
RepositoryEntry courseRe = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
List<Identity> identitiesWithData = course.getCourseEnvironment().getCoursePropertyManager().getAllIdentitiesWithCourseAssessmentData(null);
efficiencyStatementManager.updateEfficiencyStatements(courseRe, identitiesWithData);
} else {
// delete really the efficiencies of the users.
RepositoryEntry courseRepoEntry = RepositoryManager.getInstance().lookupRepositoryEntry(course, true);
efficiencyStatementManager.deleteEfficiencyStatementsFromCourse(courseRepoEntry.getKey());
}
// inform everybody else
EventBus eventBus = CoordinatorManager.getInstance().getCoordinator().getEventBus();
CourseConfigEvent courseConfigEvent = new CourseConfigEvent(CourseConfigType.efficiencyStatement, course.getResourceableId());
eventBus.fireEventToListenersOf(courseConfigEvent, course);
ILoggingAction loggingAction = enableEfficiencyStatment ? LearningResourceLoggingAction.REPOSITORY_ENTRY_PROPERTIES_EFFICIENCY_STATEMENT_ENABLED : LearningResourceLoggingAction.REPOSITORY_ENTRY_PROPERTIES_EFFICIENCY_STATEMENT_DISABLED;
ThreadLocalUserActivityLogger.log(loggingAction, getClass());
}
fireEvent(ureq, Event.CHANGED_EVENT);
}
use of org.olat.core.util.event.EventBus in project openolat by klemens.
the class PublishProcess method applyPublishSet.
/**
* @param identity
* @param locale
* @param newCourse Optimization for new courses, it doesn't call upddateOnPublish of inserted/updated course nodes
*/
public void applyPublishSet(Identity identity, Locale locale, boolean newCourse) {
// the active runstructure and the new created runstructure
Structure existingCourseRun = course.getRunStructure();
EventBus orec = CoordinatorManager.getInstance().getCoordinator().getEventBus();
/*
* use book keeping lists for publish event
*/
Set<String> deletedCourseNodeIds = new HashSet<String>();
if (editorModelDeletedNodes.size() > 0) {
for (Iterator<CourseEditorTreeNode> iter = editorModelDeletedNodes.iterator(); iter.hasNext(); ) {
CourseEditorTreeNode cetn = iter.next();
CourseNode cn = cetn.getCourseNode();
deletedCourseNodeIds.add(cn.getIdent());
}
}
Set<String> insertedCourseNodeIds = new HashSet<String>();
if (editorModelInsertedNodes.size() > 0) {
for (Iterator<CourseEditorTreeNode> iter = editorModelInsertedNodes.iterator(); iter.hasNext(); ) {
CourseEditorTreeNode cetn = iter.next();
CourseNode cn = cetn.getCourseNode();
insertedCourseNodeIds.add(cn.getIdent());
}
}
Set<String> modifiedCourseNodeIds = new HashSet<String>();
if (editorModelModifiedNodes.size() > 0) {
for (Iterator<CourseEditorTreeNode> iter = editorModelModifiedNodes.iterator(); iter.hasNext(); ) {
CourseEditorTreeNode cetn = iter.next();
CourseNode cn = cetn.getCourseNode();
modifiedCourseNodeIds.add(cn.getIdent());
}
}
/*
* broadcast PRE PUBLISH event that a publish will take place
*/
PublishEvent beforePublish = new PublishEvent(course, identity);
beforePublish.setDeletedCourseNodeIds(deletedCourseNodeIds);
beforePublish.setInsertedCourseNodeIds(insertedCourseNodeIds);
beforePublish.setModifiedCourseNodeIds(modifiedCourseNodeIds);
beforePublish.setState(PublishEvent.PRE_PUBLISH);
// old course structure accessible
orec.fireEventToListenersOf(beforePublish, course);
/*
* TODO:pb: discuss with fj: listeners could add information to
* beforePublish event such as a right to veto or add identities who is
* currently in the course, thus stopping the publishing author from
* publishing! i.e. if people are in a test or something like this.... we
* could the ask here beforePublish.accepted() and proceed only in this
* case.
*/
//
/*
* remove new nodes which were marked as delete and deletion is published.
*/
UserManager um = UserManager.getInstance();
String charset = um.getUserCharset(identity);
if (editorModelDeletedNodes.size() > 0) {
for (Iterator<CourseEditorTreeNode> iter = editorModelDeletedNodes.iterator(); iter.hasNext(); ) {
CourseEditorTreeNode cetn = iter.next();
CourseNode cn = cetn.getCourseNode();
CourseNode oldCn = existingCourseRun.getNode(cetn.getIdent());
// null
if (oldCn != null) {
if (!(cn.getIdent().equals(oldCn.getIdent()))) {
throw new AssertException("deleted cn.getIdent != oldCn.getIdent");
}
}
cetn.removeFromParent();
if (!cetn.isNewnode() && oldCn != null) {
// only clean up and archive of nodes which were already in run
// save data, remove references
deleteRefs(oldCn);
archiveDeletedNode(identity, cn, oldCn, locale, charset);
// 2) delete all user data
oldCn.cleanupOnDelete(course);
}
}
}
/*
* mark modified ones as no longer dirty
*/
if (editorModelModifiedNodes.size() > 0) {
for (Iterator<CourseEditorTreeNode> iter = editorModelModifiedNodes.iterator(); iter.hasNext(); ) {
CourseEditorTreeNode cetn = iter.next();
CourseNode cn = cetn.getCourseNode();
CourseNode oldCn = existingCourseRun.getNode(cetn.getIdent());
// null
if (oldCn != null) {
if (!(cn.getIdent().equals(oldCn.getIdent()))) {
throw new AssertException("deleted cn.getIdent != oldCn.getIdent");
}
}
cetn.setDirty(false);
//
updateRefs(cn, oldCn);
}
}
/*
* mark newly published ones is no longer new and dirty
*/
if (editorModelInsertedNodes.size() > 0) {
for (Iterator<CourseEditorTreeNode> iter = editorModelInsertedNodes.iterator(); iter.hasNext(); ) {
CourseEditorTreeNode cetn = iter.next();
CourseNode cn = cetn.getCourseNode();
CourseNode oldCn = existingCourseRun.getNode(cetn.getIdent());
if (oldCn != null) {
throw new AssertException("new node has an oldCN??");
}
cetn.setDirty(false);
cetn.setNewnode(false);
//
updateRefs(cn, null);
}
}
/*
* saving
*/
long pubtimestamp = System.currentTimeMillis();
editorTreeModel.setLatestPublishTimestamp(pubtimestamp);
// set the new runstructure and save it.
existingCourseRun.setRootNode(resultingCourseRun.getRootNode());
CourseFactory.saveCourse(course.getResourceableId());
// on old course, apply update to published nodes
if (!newCourse) {
for (CourseEditorTreeNode cetn : editorModelInsertedNodes) {
cetn.getCourseNode().updateOnPublish(locale, course, identity, publishEvents);
}
for (CourseEditorTreeNode cetn : editorModelModifiedNodes) {
cetn.getCourseNode().updateOnPublish(locale, course, identity, publishEvents);
}
}
// commit all changes before sending an event
DBFactory.getInstance().commitAndCloseSession();
/*
* broadcast event
*/
PublishEvent publishEvent = new PublishEvent(course, identity);
publishEvent.setDeletedCourseNodeIds(deletedCourseNodeIds);
publishEvent.setInsertedCourseNodeIds(insertedCourseNodeIds);
publishEvent.setModifiedCourseNodeIds(modifiedCourseNodeIds);
// new course structure accessible
// CourseFactory is one listener, which removes the course from the
// cache.
orec.fireEventToListenersOf(publishEvent, course);
/*
* END NEW STYLE PUBLISH
*/
}
use of org.olat.core.util.event.EventBus in project OpenOLAT by OpenOLAT.
the class RepositoryManager method sendDeferredEvents.
private void sendDeferredEvents(List<? extends MultiUserEvent> events, OLATResourceable ores) {
EventBus eventBus = CoordinatorManager.getInstance().getCoordinator().getEventBus();
for (MultiUserEvent event : events) {
eventBus.fireEventToListenersOf(event, ores);
eventBus.fireEventToListenersOf(event, OresHelper.lookupType(RepositoryEntry.class));
}
}
use of org.olat.core.util.event.EventBus in project OpenOLAT by OpenOLAT.
the class InfoMessageManager method setInfoMessage.
/**
* @param message The new info message that will show up on the login screen
* Synchronized to prevent two users creating or updating the info message property
* at the same time
*/
public void setInfoMessage(final String message) {
// o_clusterOK synchronized
OLATResourceable ores = OresHelper.createOLATResourceableInstance(INFO_MSG, KEY);
coordinatorManager.getCoordinator().getSyncer().doInSync(ores, new SyncerExecutor() {
public void execute() {
PropertyManager pm = PropertyManager.getInstance();
Property p = pm.findProperty(null, null, null, "_o3_", INFO_MSG);
if (p == null) {
p = pm.createPropertyInstance(null, null, null, "_o3_", INFO_MSG, null, null, null, "");
pm.saveProperty(p);
}
p.setTextValue(message);
// set Message in RAM
InfoMessageManager.infoMessage = message;
pm.updateProperty(p);
}
});
// end syncerCallback
EventBus eb = coordinatorManager.getCoordinator().getEventBus();
MultiUserEvent mue = new MultiUserEvent(message);
eb.fireEventToListenersOf(mue, INFO_MESSAGE_ORES);
}
use of org.olat.core.util.event.EventBus in project OpenOLAT by OpenOLAT.
the class PublishProcess method applyPublishSet.
/**
* @param identity
* @param locale
* @param newCourse Optimization for new courses, it doesn't call upddateOnPublish of inserted/updated course nodes
*/
public void applyPublishSet(Identity identity, Locale locale, boolean newCourse) {
// the active runstructure and the new created runstructure
Structure existingCourseRun = course.getRunStructure();
EventBus orec = CoordinatorManager.getInstance().getCoordinator().getEventBus();
/*
* use book keeping lists for publish event
*/
Set<String> deletedCourseNodeIds = new HashSet<String>();
if (editorModelDeletedNodes.size() > 0) {
for (Iterator<CourseEditorTreeNode> iter = editorModelDeletedNodes.iterator(); iter.hasNext(); ) {
CourseEditorTreeNode cetn = iter.next();
CourseNode cn = cetn.getCourseNode();
deletedCourseNodeIds.add(cn.getIdent());
}
}
Set<String> insertedCourseNodeIds = new HashSet<String>();
if (editorModelInsertedNodes.size() > 0) {
for (Iterator<CourseEditorTreeNode> iter = editorModelInsertedNodes.iterator(); iter.hasNext(); ) {
CourseEditorTreeNode cetn = iter.next();
CourseNode cn = cetn.getCourseNode();
insertedCourseNodeIds.add(cn.getIdent());
}
}
Set<String> modifiedCourseNodeIds = new HashSet<String>();
if (editorModelModifiedNodes.size() > 0) {
for (Iterator<CourseEditorTreeNode> iter = editorModelModifiedNodes.iterator(); iter.hasNext(); ) {
CourseEditorTreeNode cetn = iter.next();
CourseNode cn = cetn.getCourseNode();
modifiedCourseNodeIds.add(cn.getIdent());
}
}
/*
* broadcast PRE PUBLISH event that a publish will take place
*/
PublishEvent beforePublish = new PublishEvent(course, identity);
beforePublish.setDeletedCourseNodeIds(deletedCourseNodeIds);
beforePublish.setInsertedCourseNodeIds(insertedCourseNodeIds);
beforePublish.setModifiedCourseNodeIds(modifiedCourseNodeIds);
beforePublish.setState(PublishEvent.PRE_PUBLISH);
// old course structure accessible
orec.fireEventToListenersOf(beforePublish, course);
/*
* TODO:pb: discuss with fj: listeners could add information to
* beforePublish event such as a right to veto or add identities who is
* currently in the course, thus stopping the publishing author from
* publishing! i.e. if people are in a test or something like this.... we
* could the ask here beforePublish.accepted() and proceed only in this
* case.
*/
//
/*
* remove new nodes which were marked as delete and deletion is published.
*/
UserManager um = UserManager.getInstance();
String charset = um.getUserCharset(identity);
if (editorModelDeletedNodes.size() > 0) {
for (Iterator<CourseEditorTreeNode> iter = editorModelDeletedNodes.iterator(); iter.hasNext(); ) {
CourseEditorTreeNode cetn = iter.next();
CourseNode cn = cetn.getCourseNode();
CourseNode oldCn = existingCourseRun.getNode(cetn.getIdent());
// null
if (oldCn != null) {
if (!(cn.getIdent().equals(oldCn.getIdent()))) {
throw new AssertException("deleted cn.getIdent != oldCn.getIdent");
}
}
cetn.removeFromParent();
if (!cetn.isNewnode() && oldCn != null) {
// only clean up and archive of nodes which were already in run
// save data, remove references
deleteRefs(oldCn);
archiveDeletedNode(identity, cn, oldCn, locale, charset);
// 2) delete all user data
oldCn.cleanupOnDelete(course);
}
}
}
/*
* mark modified ones as no longer dirty
*/
if (editorModelModifiedNodes.size() > 0) {
for (Iterator<CourseEditorTreeNode> iter = editorModelModifiedNodes.iterator(); iter.hasNext(); ) {
CourseEditorTreeNode cetn = iter.next();
CourseNode cn = cetn.getCourseNode();
CourseNode oldCn = existingCourseRun.getNode(cetn.getIdent());
// null
if (oldCn != null) {
if (!(cn.getIdent().equals(oldCn.getIdent()))) {
throw new AssertException("deleted cn.getIdent != oldCn.getIdent");
}
}
cetn.setDirty(false);
//
updateRefs(cn, oldCn);
}
}
/*
* mark newly published ones is no longer new and dirty
*/
if (editorModelInsertedNodes.size() > 0) {
for (Iterator<CourseEditorTreeNode> iter = editorModelInsertedNodes.iterator(); iter.hasNext(); ) {
CourseEditorTreeNode cetn = iter.next();
CourseNode cn = cetn.getCourseNode();
CourseNode oldCn = existingCourseRun.getNode(cetn.getIdent());
if (oldCn != null) {
throw new AssertException("new node has an oldCN??");
}
cetn.setDirty(false);
cetn.setNewnode(false);
//
updateRefs(cn, null);
}
}
/*
* saving
*/
long pubtimestamp = System.currentTimeMillis();
editorTreeModel.setLatestPublishTimestamp(pubtimestamp);
// set the new runstructure and save it.
existingCourseRun.setRootNode(resultingCourseRun.getRootNode());
CourseFactory.saveCourse(course.getResourceableId());
// on old course, apply update to published nodes
if (!newCourse) {
for (CourseEditorTreeNode cetn : editorModelInsertedNodes) {
cetn.getCourseNode().updateOnPublish(locale, course, identity, publishEvents);
}
for (CourseEditorTreeNode cetn : editorModelModifiedNodes) {
cetn.getCourseNode().updateOnPublish(locale, course, identity, publishEvents);
}
}
// commit all changes before sending an event
DBFactory.getInstance().commitAndCloseSession();
/*
* broadcast event
*/
PublishEvent publishEvent = new PublishEvent(course, identity);
publishEvent.setDeletedCourseNodeIds(deletedCourseNodeIds);
publishEvent.setInsertedCourseNodeIds(insertedCourseNodeIds);
publishEvent.setModifiedCourseNodeIds(modifiedCourseNodeIds);
// new course structure accessible
// CourseFactory is one listener, which removes the course from the
// cache.
orec.fireEventToListenersOf(publishEvent, course);
/*
* END NEW STYLE PUBLISH
*/
}
Aggregations