use of org.olat.core.util.event.MultiUserEvent in project OpenOLAT by OpenOLAT.
the class RepositoryEditDescriptionController method formOK.
@Override
protected void formOK(UserRequest ureq) {
if (licenseModule.isEnabled(licenseHandler)) {
if (licenseEl != null && licenseEl.isOneSelected()) {
String licenseTypeKey = licenseEl.getSelectedKey();
LicenseType licneseType = licenseService.loadLicenseTypeByKey(licenseTypeKey);
license.setLicenseType(licneseType);
}
String licensor = null;
String freetext = null;
if (licensorEl != null && licensorEl.isVisible()) {
licensor = StringHelper.containsNonWhitespace(licensorEl.getValue()) ? licensorEl.getValue() : null;
}
if (licenseFreetextEl != null && licenseFreetextEl.isVisible()) {
freetext = StringHelper.containsNonWhitespace(licenseFreetextEl.getValue()) ? licenseFreetextEl.getValue() : null;
}
license.setLicensor(licensor);
license.setFreetext(freetext);
license = licenseService.update(license);
licensorEl.setValue(license.getLicensor());
licenseFreetextEl.setValue(license.getFreetext());
}
File uploadedImage = fileUpload.getUploadFile();
if (uploadedImage != null && uploadedImage.exists()) {
VFSContainer tmpHome = new LocalFolderImpl(new File(WebappHelper.getTmpDir()));
VFSContainer container = tmpHome.createChildContainer(UUID.randomUUID().toString());
// give it it's real name and extension
VFSLeaf newFile = fileUpload.moveUploadFileTo(container);
boolean ok = repositoryManager.setImage(newFile, repositoryEntry);
if (!ok) {
showWarning("cif.error.image");
} else {
VFSLeaf image = repositoryManager.getImage(repositoryEntry);
if (image instanceof LocalFileImpl) {
fileUpload.setInitialFile(((LocalFileImpl) image).getBasefile());
}
}
container.delete();
}
File uploadedMovie = movieUpload.getUploadFile();
if (uploadedMovie != null && uploadedMovie.exists()) {
VFSContainer m = (VFSContainer) mediaContainer.resolve("media");
VFSLeaf newFile = movieUpload.moveUploadFileTo(m);
if (newFile == null) {
showWarning("cif.error.movie");
} else {
String filename = movieUpload.getUploadFileName();
String extension = FileUtils.getFileSuffix(filename);
newFile.rename(repositoryEntry.getKey() + "." + extension);
}
}
String displayname = displayName.getValue().trim();
repositoryEntry.setDisplayname(displayname);
String mainLanguage = language.getValue();
if (StringHelper.containsNonWhitespace(mainLanguage)) {
repositoryEntry.setMainLanguage(mainLanguage);
} else {
repositoryEntry.setMainLanguage(null);
}
if (dateTypesEl != null) {
String type = "none";
if (dateTypesEl.isOneSelected()) {
type = dateTypesEl.getSelectedKey();
}
if ("none".equals(type)) {
repositoryEntry.setLifecycle(null);
} else if ("public".equals(type)) {
String key = publicDatesEl.getSelectedKey();
if (StringHelper.isLong(key)) {
Long cycleKey = Long.parseLong(key);
RepositoryEntryLifecycle cycle = lifecycleDao.loadById(cycleKey);
repositoryEntry.setLifecycle(cycle);
}
} else if ("private".equals(type)) {
Date start = startDateEl.getDate();
Date end = endDateEl.getDate();
RepositoryEntryLifecycle cycle = repositoryEntry.getLifecycle();
if (cycle == null || !cycle.isPrivateCycle()) {
String softKey = "lf_" + repositoryEntry.getSoftkey();
cycle = lifecycleDao.create(displayname, softKey, true, start, end);
} else {
cycle.setValidFrom(start);
cycle.setValidTo(end);
cycle = lifecycleDao.updateLifecycle(cycle);
}
repositoryEntry.setLifecycle(cycle);
}
}
if (externalRef != null && externalRef.isEnabled()) {
String ref = externalRef.getValue().trim();
repositoryEntry.setExternalRef(ref);
}
String desc = description.getValue().trim();
repositoryEntry.setDescription(desc);
if (authors != null) {
String auth = authors.getValue().trim();
repositoryEntry.setAuthors(auth);
}
if (objectives != null) {
String obj = objectives.getValue().trim();
repositoryEntry.setObjectives(obj);
}
if (requirements != null) {
String req = requirements.getValue().trim();
repositoryEntry.setRequirements(req);
}
if (credits != null) {
String cred = credits.getValue().trim();
repositoryEntry.setCredits(cred);
}
if (expenditureOfWork != null) {
String exp = expenditureOfWork.getValue().trim();
repositoryEntry.setExpenditureOfWork(exp);
}
if (location != null) {
String loc = location.getValue().trim();
repositoryEntry.setLocation(loc);
}
repositoryEntry = repositoryManager.setDescriptionAndName(repositoryEntry, repositoryEntry.getDisplayname(), repositoryEntry.getExternalRef(), repositoryEntry.getAuthors(), repositoryEntry.getDescription(), repositoryEntry.getObjectives(), repositoryEntry.getRequirements(), repositoryEntry.getCredits(), repositoryEntry.getMainLanguage(), repositoryEntry.getLocation(), repositoryEntry.getExpenditureOfWork(), repositoryEntry.getLifecycle());
if (repositoryEntry == null) {
showWarning("repositoryentry.not.existing");
fireEvent(ureq, Event.CLOSE_EVENT);
} else {
fireEvent(ureq, Event.CHANGED_EVENT);
MultiUserEvent modifiedEvent = new EntryChangedEvent(repositoryEntry, getIdentity(), Change.modifiedDescription, "authoring");
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(modifiedEvent, RepositoryService.REPOSITORY_EVENT_ORES);
}
}
use of org.olat.core.util.event.MultiUserEvent in project OpenOLAT by OpenOLAT.
the class ENEditGroupAreaFormController method event.
@Override
protected void event(UserRequest ureq, Controller source, Event event) {
subm.setEnabled(true);
if (source == groupChooseC) {
if (event == Event.DONE_EVENT) {
cmc.deactivate();
KeysAndNames c = getGroupKeysAndNames(groupChooseC.getSelectedKeys());
easyGroupList.setValue(c.getDecoratedNames());
easyGroupList.setUserObject(c);
easyGroupList.getRootForm().submit(ureq);
chooseGroupsLink.setI18nKey("choose");
} else if (Event.CANCELLED_EVENT == event) {
cmc.deactivate();
}
} else if (source == areaChooseC) {
if (event == Event.DONE_EVENT) {
cmc.deactivate();
KeysAndNames c = getAreaKeysAndNames(areaChooseC.getSelectedKeys());
easyAreaList.setValue(c.getDecoratedNames());
easyAreaList.setUserObject(c);
easyAreaList.getRootForm().submit(ureq);
chooseAreasLink.setI18nKey("choose");
} else if (event == Event.CANCELLED_EVENT) {
cmc.deactivate();
}
} else if (source == groupCreateCntrllr) {
easyGroupList.setEnabled(true);
cmc.deactivate();
if (event == Event.DONE_EVENT) {
List<Long> c = new ArrayList<Long>();
c.addAll(getKeys(easyGroupList));
if (fixGroupError != null && fixGroupError.getUserObject() != null) {
String[] keyArr = (String[]) fixGroupError.getUserObject();
if (keyArr != null && keyArr.length > 0) {
List<Long> fixedKeys = toKeys(keyArr[0]);
c.removeAll(fixedKeys);
}
}
c.addAll(groupCreateCntrllr.getCreatedGroupKeys());
KeysAndNames keysAndNames = getGroupKeysAndNames(c);
easyGroupList.setValue(keysAndNames.getDecoratedNames());
easyGroupList.setUserObject(keysAndNames);
if (groupCreateCntrllr.getCreatedGroupNames().size() > 0 && !hasGroups) {
chooseGroupsLink.setLinkTitle("select");
singleUserEventCenter.fireEventToListenersOf(new MultiUserEvent("changed"), groupConfigChangeEventOres);
}
easyGroupList.getRootForm().submit(ureq);
}
} else if (source == areaCreateCntrllr) {
easyAreaList.setEnabled(true);
cmc.deactivate();
if (event == Event.DONE_EVENT) {
List<Long> c = new ArrayList<Long>();
c.addAll(getKeys(easyAreaList));
if (fixAreaError != null && fixAreaError.getUserObject() != null) {
String[] keyArr = (String[]) fixAreaError.getUserObject();
if (keyArr != null && keyArr.length > 0) {
List<Long> fixedKeys = toKeys(keyArr[0]);
c.removeAll(fixedKeys);
}
}
c.addAll(areaCreateCntrllr.getCreatedAreaKeys());
KeysAndNames keysAndNames = getAreaKeysAndNames(c);
easyAreaList.setValue(keysAndNames.getDecoratedNames());
easyAreaList.setUserObject(keysAndNames);
if (areaCreateCntrllr.getCreatedAreaNames().size() > 0 && !hasAreas) {
chooseAreasLink.setLinkTitle("select");
singleUserEventCenter.fireEventToListenersOf(new MultiUserEvent("changed"), groupConfigChangeEventOres);
}
easyAreaList.getRootForm().submit(ureq);
}
}
}
use of org.olat.core.util.event.MultiUserEvent in project OpenOLAT by OpenOLAT.
the class ProjectGroupManagerImpl method sendGroupChangeEvent.
@Override
public void sendGroupChangeEvent(Project project, Long courseResourceableId, Identity identity) {
ICourse course = CourseFactory.loadCourse(courseResourceableId);
RepositoryEntry ores = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
MultiUserEvent modifiedEvent = new BusinessGroupModifiedEvent(BusinessGroupModifiedEvent.IDENTITY_ADDED_EVENT, project.getProjectGroup(), identity);
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(modifiedEvent, ores);
}
use of org.olat.core.util.event.MultiUserEvent in project OpenOLAT by OpenOLAT.
the class ClusterAdminControllerCluster method event.
@Override
protected void event(UserRequest ureq, Component source, Event event) {
if (source == syncLong) {
// sync on a olatresourceable and hold the lock for 5 seconds.
CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(ORES_TEST, new SyncerExecutor() {
public void execute() {
sleep(5000);
}
});
// the runnable is executed within the same thread->
getWindowControl().setInfo("done syncing on the test olatresourceable for 5 seconds");
} else if (source == syncShort) {
// sync on a olatresourceable and hold the lock for 1 second.
CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(ORES_TEST, new SyncerExecutor() {
public void execute() {
sleep(1000);
}
});
// the runnable is executed within the same thread->
getWindowControl().setInfo("done syncing on the test olatresourceable for 1 second");
} else if (source == testPerf) {
// send 1000 (short) messages over the cluster bus
int cnt = 1000;
long start = System.nanoTime();
for (int i = 0; i < cnt; i++) {
clusBus.fireEventToListenersOf(new MultiUserEvent("jms-perf-test-" + i + " of " + cnt), ORES_TEST);
}
long stop = System.nanoTime();
long dur = stop - start;
double inmilis = dur / 1000000;
double avg = dur / cnt;
double avgmilis = avg / 1000000;
getWindowControl().setInfo("sending " + cnt + " messages took " + inmilis + " ms, avg per messages was " + avg + " ns = " + avgmilis + " ms");
} else if (source == testCachePut) {
CacheWrapper<String, String> cw = CoordinatorManager.getInstance().getCoordinator().getCacher().getCache(this.getClass().getSimpleName(), "cachetest");
// we explicitly use put and not putSilent to show that a put invalidates (and thus removes) this key of this cache in all other cluster nodes.
cw.update("akey", "hello");
updateCacheInfo();
} else if (source == testCachePut2) {
// we explicitly use put and not putSilent to show that a put invalidates (and thus removes) this key of this cache in all other cluster nodes.
CacheWrapper<String, String> cw = CoordinatorManager.getInstance().getCoordinator().getCacher().getCache(this.getClass().getSimpleName(), "cachetest");
cw.update("akey", "world");
updateCacheInfo();
} else if (source == testSFUPerf) {
// acquire a sync 1000x times (does internally a select-for-update on the database)
int cnt = 1000;
long start = System.nanoTime();
for (int i = 0; i < cnt; i++) {
CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(ORES_TEST, new SyncerExecutor() {
public void execute() {
// empty
}
});
}
long stop = System.nanoTime();
long dur = stop - start;
double inmilis = dur / 1000000;
double avg = dur / cnt;
double avgmilis = avg / 1000000;
getWindowControl().setInfo("acquiring " + cnt + " locks for syncing (using db's \"select for update\") took " + inmilis + " ms, avg per messages was " + avg + " ns = " + avgmilis + " ms");
} else if (source == releaseAllLocksFor) {
// let a user search pop up
usc = new UserSearchController(ureq, getWindowControl(), true);
listenTo(usc);
getWindowControl().pushAsModalDialog(usc.getInitialComponent());
} else if ((source == nodeInfoVc) && (event.getCommand().equals("switchToNode"))) {
String nodeIdStr = ureq.getHttpReq().getParameter("nodeId");
if (nodeIdStr.length() == 1) {
nodeIdStr = "0" + nodeIdStr;
}
Cookie[] cookies = ureq.getHttpReq().getCookies();
for (int i = 0; i < cookies.length; i++) {
Cookie cookie = cookies[i];
if ("JSESSIONID".equals(cookie.getName())) {
String redirectedButInvalidSessionId = cookie.getValue();
redirectedButInvalidSessionId = redirectedButInvalidSessionId.substring(0, redirectedButInvalidSessionId.length() - 2) + nodeIdStr;
logInfo("redirecting session to node " + nodeIdStr + ", new sessionid=" + redirectedButInvalidSessionId, null);
cookie.setValue(redirectedButInvalidSessionId);
replaceCookie(ureq.getHttpReq(), ureq.getHttpResp(), cookie);
// OLAT-5165: make sure we can always bypass the dmz reject mechanism (for 5min that is)
Cookie newCookie = new Cookie("bypassdmzreject", String.valueOf(System.currentTimeMillis()));
// 5min lifetime
newCookie.setMaxAge(5 * 60);
newCookie.setPath(WebappHelper.getServletContextPath());
newCookie.setSecure(ureq.getHttpReq().isSecure());
newCookie.setComment("cookie allowing olat admin users to bypass dmz rejects");
ureq.getHttpResp().addCookie(newCookie);
OncePanel oncePanel = new OncePanel("refresh");
oncePanel.setContent(createVelocityContainer("refresh"));
mainVc.put("refresh", oncePanel);
break;
}
}
} else if (source == toggleStartStop) {
clusBus.resetStats();
updatePerfInfos();
} else if (source == resetStats) {
clusBus.resetStats();
updatePerfInfos();
}
}
use of org.olat.core.util.event.MultiUserEvent 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);
}
Aggregations