Search in sources :

Example 31 with OLATResourceable

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;
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) ArrayList(java.util.ArrayList) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) Date(java.util.Date) ExDate(net.fortuna.ical4j.model.property.ExDate) CalendarManager(org.olat.commons.calendar.CalendarManager) Kalendar(org.olat.commons.calendar.model.Kalendar) RecurrenceId(net.fortuna.ical4j.model.property.RecurrenceId) ParseException(java.text.ParseException) CalendarGUIModifiedEvent(org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent)

Example 32 with OLATResourceable

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();
}
Also used : CalendarManager(org.olat.commons.calendar.CalendarManager) Kalendar(org.olat.commons.calendar.model.Kalendar) OLATResourceable(org.olat.core.id.OLATResourceable) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) Date(java.util.Date) ExDate(net.fortuna.ical4j.model.property.ExDate) CalendarGUIModifiedEvent(org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent)

Example 33 with OLATResourceable

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();
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar) OLATResourceable(org.olat.core.id.OLATResourceable) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) KalendarEventKey(org.olat.commons.calendar.model.KalendarEventKey) Map(java.util.Map) HashMap(java.util.HashMap) CalendarGUIModifiedEvent(org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent)

Example 34 with OLATResourceable

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);
    }
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) TableController(org.olat.core.gui.components.table.TableController) TableGuiConfiguration(org.olat.core.gui.components.table.TableGuiConfiguration) WindowControl(org.olat.core.gui.control.WindowControl)

Example 35 with OLATResourceable

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);
}
Also used : AssertException(org.olat.core.logging.AssertException) OLATResourceable(org.olat.core.id.OLATResourceable) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer)

Aggregations

OLATResourceable (org.olat.core.id.OLATResourceable)924 WindowControl (org.olat.core.gui.control.WindowControl)304 Test (org.junit.Test)158 Identity (org.olat.core.id.Identity)154 RepositoryEntry (org.olat.repository.RepositoryEntry)130 ContextEntry (org.olat.core.id.context.ContextEntry)82 ArrayList (java.util.ArrayList)68 OLATResource (org.olat.resource.OLATResource)60 Controller (org.olat.core.gui.control.Controller)48 Date (java.util.Date)46 AssertException (org.olat.core.logging.AssertException)32 StateSite (org.olat.core.id.context.StateSite)30 SyncerExecutor (org.olat.core.util.coordinate.SyncerExecutor)30 ICourse (org.olat.course.ICourse)30 CourseNode (org.olat.course.nodes.CourseNode)28 DBCheckbox (org.olat.course.nodes.cl.model.DBCheckbox)28 BusinessControl (org.olat.core.id.context.BusinessControl)24 BusinessGroup (org.olat.group.BusinessGroup)24 LayoutMain3ColsController (org.olat.core.commons.fullWebApp.LayoutMain3ColsController)22 BinderSecurityCallback (org.olat.modules.portfolio.BinderSecurityCallback)22