use of org.olat.core.id.OLATResourceable in project OpenOLAT by OpenOLAT.
the class ICalFileCalendarManager method updateEventAlreadyInSync.
/**
* @see org.olat.commons.calendar.CalendarManager#updateEventFrom(org.olat.commons.calendar.model.Kalendar, org.olat.commons.calendar.model.KalendarEvent)
*/
@Override
public boolean updateEventAlreadyInSync(final Kalendar cal, final KalendarEvent kalendarEvent) {
OLATResourceable calOres = getOresHelperFor(cal);
CoordinatorManager.getInstance().getCoordinator().getSyncer().assertAlreadyDoInSyncFor(calOres);
Kalendar reloadedCal = getCalendarFromCache(cal.getType(), cal.getCalendarID());
if (StringHelper.containsNonWhitespace(kalendarEvent.getRecurrenceRule())) {
Date oldBegin = kalendarEvent.getImmutableBegin();
Date oldEnd = kalendarEvent.getImmutableEnd();
KalendarEvent originalEvent = reloadedCal.getEvent(kalendarEvent.getID(), null);
Date newBegin = kalendarEvent.getBegin();
Date newEnd = kalendarEvent.getEnd();
long beginDiff = newBegin.getTime() - oldBegin.getTime();
long endDiff = newEnd.getTime() - oldEnd.getTime();
java.util.Calendar cl = java.util.Calendar.getInstance();
cl.setTime(originalEvent.getBegin());
cl.add(java.util.Calendar.MILLISECOND, (int) beginDiff);
kalendarEvent.setBegin(cl.getTime());
cl.setTime(originalEvent.getEnd());
cl.add(java.util.Calendar.MILLISECOND, (int) endDiff);
kalendarEvent.setEnd(cl.getTime());
List<KalendarEvent> exEvents = new ArrayList<>();
List<KalendarEvent> allEvents = reloadedCal.getEvents();
for (KalendarEvent event : allEvents) {
if (event.getID().equals(kalendarEvent.getID()) && StringHelper.containsNonWhitespace(event.getRecurrenceID())) {
exEvents.add(event);
}
}
if (exEvents.size() > 0) {
for (KalendarEvent exEvent : exEvents) {
try {
reloadedCal.removeEvent(exEvent);
String recurrenceId = exEvent.getRecurrenceID();
RecurrenceId recurId = new RecurrenceId(recurrenceId, tz);
Date currentRecurrence = recurId.getDate();
java.util.Calendar calc = java.util.Calendar.getInstance();
calc.clear();
calc.setTime(currentRecurrence);
if (beginDiff > 0) {
calc.add(java.util.Calendar.MILLISECOND, (int) beginDiff);
}
Date newRecurrenceDate = calc.getTime();
boolean allDay = kalendarEvent.isAllDayEvent();
RecurrenceId newRecurId;
if (allDay) {
newRecurId = new RecurrenceId(tz);
newRecurId.setDate(CalendarUtils.createDate(newRecurrenceDate));
} else {
String startString = CalendarUtils.formatRecurrenceDate(newRecurrenceDate, false);
newRecurId = new RecurrenceId(startString, tz);
}
exEvent.setRecurrenceID(newRecurId.getValue());
reloadedCal.addEvent(exEvent);
} catch (ParseException e) {
log.error("", e);
}
}
}
}
// remove old event
reloadedCal.removeEvent(kalendarEvent);
kalendarEvent.resetImmutableDates();
// add changed event
reloadedCal.addEvent(kalendarEvent);
boolean successfullyPersist = persistCalendar(reloadedCal);
// inform all controller about calendar change for reload
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CalendarGUIModifiedEvent(cal), OresHelper.lookupType(CalendarManager.class));
return successfullyPersist;
}
use of org.olat.core.id.OLATResourceable in project OpenOLAT by OpenOLAT.
the class ICalFileCalendarManager method removeOccurenceOfEvent.
@Override
public boolean removeOccurenceOfEvent(final Kalendar cal, final KalendarRecurEvent kalendarEvent) {
OLATResourceable calOres = getOresHelperFor(cal);
Boolean removeSuccessful = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(calOres, new SyncerCallback<Boolean>() {
@Override
public Boolean execute() {
String uid = kalendarEvent.getID();
Date occurenceDate = kalendarEvent.getBegin();
Kalendar loadedCal = getCalendarFromCache(cal.getType(), cal.getCalendarID());
KalendarEvent rootEvent = loadedCal.getEvent(kalendarEvent.getID(), null);
rootEvent.addRecurrenceExc(kalendarEvent.getBegin());
for (KalendarEvent kEvent : loadedCal.getEvents()) {
if (uid.equals(kEvent.getID()) && kEvent.getOccurenceDate() != null && occurenceDate.equals(kEvent.getOccurenceDate())) {
loadedCal.removeEvent(kEvent);
}
}
boolean successfullyPersist = persistCalendar(loadedCal);
return new Boolean(successfullyPersist);
}
});
// inform all controller about calendar change for reload
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CalendarGUIModifiedEvent(cal), OresHelper.lookupType(CalendarManager.class));
return removeSuccessful.booleanValue();
}
use of org.olat.core.id.OLATResourceable in project OpenOLAT by OpenOLAT.
the class ICalFileCalendarManager method updateCalendar.
@Override
public boolean updateCalendar(final Kalendar cal, final Kalendar importedCal) {
OLATResourceable calOres = getOresHelperFor(cal);
Boolean updatedSuccessful = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(calOres, new SyncerCallback<Boolean>() {
@Override
public Boolean execute() {
Map<KalendarEventKey, KalendarEvent> uidToEvent = new HashMap<>();
for (KalendarEvent event : cal.getEvents()) {
if (StringHelper.containsNonWhitespace(event.getID())) {
uidToEvent.put(new KalendarEventKey(event), event);
}
}
Kalendar loadedCal = getCalendarFromCache(cal.getType(), cal.getCalendarID());
for (KalendarEvent importedEvent : importedCal.getEvents()) {
KalendarEventKey uid = new KalendarEventKey(importedEvent);
if (uidToEvent.containsKey(uid)) {
// remove old event
loadedCal.removeEvent(importedEvent);
// add changed event
loadedCal.addEvent(importedEvent);
} else {
loadedCal.addEvent(importedEvent);
}
}
boolean successfullyPersist = persistCalendar(cal);
// inform all controller about calendar change for reload
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CalendarGUIModifiedEvent(cal), OresHelper.lookupType(CalendarManager.class));
return new Boolean(successfullyPersist);
}
});
return updatedSuccessful.booleanValue();
}
use of org.olat.core.id.OLATResourceable in project OpenOLAT by OpenOLAT.
the class UsermanagerUserSearchForm method initUserListCtr.
/**
* Initialize the table controller using the list of identities
*
* @param ureq
* @param identitiesList
*/
private void initUserListCtr(UserRequest ureq, List<Identity> myIdentities, Integer searchStatusField) {
removeAsListenerAndDispose(tableCtr);
boolean actionEnabled = true;
TableGuiConfiguration tableConfig = new TableGuiConfiguration();
tableConfig.setTableEmptyMessage(translate("error.no.user.found"));
if ((searchStatusField != null) && (searchStatusField.equals(Identity.STATUS_DELETED))) {
actionEnabled = false;
}
tableConfig.setDownloadOffered(true);
tableConfig.setPreferencesOffered(true, "ExtendedIdentitiesTable");
tableConfig.setTableEmptyMessage(translate("error.no.user.found"));
tdm = new ExtendedIdentitiesTableDataModel(ureq, myIdentities, actionEnabled);
OLATResourceable ores = OresHelper.createOLATResourceableInstance("table", 0l);
ThreadLocalUserActivityLogger.addLoggingResourceInfo(LoggingResourceable.wrapBusinessPath(ores));
WindowControl bwControl = addToHistory(ureq, ores, null);
tableCtr = new TableController(tableConfig, ureq, bwControl, getTranslator());
tdm.addColumnDescriptors(tableCtr, getTranslator());
tableCtr.setTableDataModel(tdm);
listenTo(tableCtr);
if (showEmailButton) {
tableCtr.addMultiSelectAction("command.mail", CMD_MAIL);
}
if (actionEnabled) {
tableCtr.addMultiSelectAction("action.bulkedit", CMD_BULKEDIT);
}
if (showEmailButton || actionEnabled) {
tableCtr.setMultiSelect(true);
}
}
use of org.olat.core.id.OLATResourceable in project OpenOLAT by OpenOLAT.
the class HTMLEditorController method initEditorForm.
private void initEditorForm(VFSContainer bContainer, String relFilePath, CustomLinkTreeModel linkTreeModel, String mPath, boolean editorCheck, boolean versions, boolean withButtons) {
this.baseContainer = bContainer;
this.fileRelPath = relFilePath;
this.mediaPath = mPath;
this.versionsEnabled = versions;
this.buttonsEnabled = withButtons;
this.customLinkTreeModel = linkTreeModel;
this.editorCheckEnabled = editorCheck;
// make sure the filename doesn't start with a slash
this.fileName = ((relFilePath.charAt(0) == '/') ? relFilePath.substring(1) : relFilePath);
this.fileLeaf = (VFSLeaf) bContainer.resolve(fileName);
if (fileLeaf == null)
throw new AssertException("file::" + getFileDebuggingPath(bContainer, relFilePath) + " does not exist!");
long size = fileLeaf.getSize();
if (size > FolderConfig.getMaxEditSizeLimit()) {
// limit to reasonable size, see OO-57
fileToLargeError = translate("plaintext.error.tolarge", new String[] { (size / 1000) + "", (FolderConfig.getMaxEditSizeLimit() / 1000) + "" });
this.body = "";
this.editable = false;
return;
}
// check if someone else is already editing the file
if (fileLeaf instanceof LocalFileImpl) {
// Cast to LocalFile necessary because the VFSItem is missing some
// ID mechanism that identifies an item within the system
OLATResourceable lockResourceable = createLockResourceable(fileLeaf);
// OLAT-5066: the use of "fileName" gives users the (false) impression that the file they wish to access
// is already locked by someone else. Since the lock token must be smaller than 50 characters we us an
// MD5 hash of the absolute file path which will always be 32 characters long and virtually unique.
String lockToken = createLockToken(bContainer, relFilePath);
lock = CoordinatorManager.getInstance().getCoordinator().getLocker().acquireLock(lockResourceable, getIdentity(), lockToken);
VelocityContainer vc = (VelocityContainer) flc.getComponent();
if (!lock.isSuccess()) {
vc.contextPut("locked", Boolean.TRUE);
String fullname = UserManager.getInstance().getUserDisplayName(lock.getOwner());
vc.contextPut("lockOwner", fullname);
editable = false;
return;
} else {
vc.contextPut("locked", Boolean.FALSE);
}
}
// Parse the content of the page
this.body = parsePage(fileLeaf);
}
Aggregations