Search in sources :

Example 1 with CalDavCalendarCollection

use of net.fortuna.ical4j.connector.dav.CalDavCalendarCollection in project borg_calendar by mikeberger.

the class CalDav method sync.

public static synchronized void sync(Integer years, boolean outward_only) throws Exception {
    CompatibilityHints.setHintEnabled(CompatibilityHints.KEY_RELAXED_PARSING, true);
    CompatibilityHints.setHintEnabled(CompatibilityHints.KEY_RELAXED_UNFOLDING, true);
    CompatibilityHints.setHintEnabled(CompatibilityHints.KEY_RELAXED_VALIDATION, true);
    CompatibilityHints.setHintEnabled(CompatibilityHints.KEY_OUTLOOK_COMPATIBILITY, true);
    System.setProperty("net.fortuna.ical4j.timezone.cache.impl", "net.fortuna.ical4j.util.MapTimeZoneCache");
    CalDavCalendarStore store = connect();
    if (store == null)
        throw new Exception("Failed to connect to CalDav Store");
    log.info("SYNC: Get Collection");
    String calname = Prefs.getPref(PrefName.CALDAV_CAL);
    CalDavCalendarCollection collection = getCollection(store, calname);
    String ctag = collection.getProperty(CSDavPropertyName.CTAG, String.class);
    log.info("SYNC: CTAG=" + ctag);
    boolean incoming_changes = true;
    String lastCtag = OptionModel.getReference().getOption(CTAG_OPTION);
    if (lastCtag != null && lastCtag.equals(ctag))
        incoming_changes = false;
    processSyncMap(collection);
    if (!incoming_changes)
        SocketClient.sendLogMessage("SYNC: no incoming changes\n");
    if (!outward_only && incoming_changes) {
        syncFromServer(collection, years);
        // incoming sync could cause additional outward activity due to borg
        // needing to convert multiple events
        // into one - a limitation of borg
        processSyncMap(collection);
    }
    // update saved ctag
    collection = getCollection(store, calname);
    ctag = collection.getProperty(CSDavPropertyName.CTAG, String.class);
    OptionModel.getReference().setOption(new Option(CTAG_OPTION, ctag));
    log.info("SYNC: NEW CTAG=" + ctag);
    // remove any remote sync event
    setServerSyncNeeded(false);
    log.info("SYNC: Done");
}
Also used : CalDavCalendarStore(net.fortuna.ical4j.connector.dav.CalDavCalendarStore) CalDavCalendarCollection(net.fortuna.ical4j.connector.dav.CalDavCalendarCollection)

Example 2 with CalDavCalendarCollection

use of net.fortuna.ical4j.connector.dav.CalDavCalendarCollection in project borg_calendar by mikeberger.

the class CalDav method export.

public static synchronized void export(Integer years) throws Exception {
    CompatibilityHints.setHintEnabled(CompatibilityHints.KEY_RELAXED_PARSING, true);
    CompatibilityHints.setHintEnabled(CompatibilityHints.KEY_RELAXED_UNFOLDING, true);
    CompatibilityHints.setHintEnabled(CompatibilityHints.KEY_RELAXED_VALIDATION, true);
    CompatibilityHints.setHintEnabled(CompatibilityHints.KEY_OUTLOOK_COMPATIBILITY, true);
    Date after = null;
    if (years != null) {
        GregorianCalendar cal = new GregorianCalendar();
        cal.add(java.util.Calendar.YEAR, -1 * years.intValue());
        after = cal.getTime();
    }
    Calendar calendar = ICal.exportIcal(after, true);
    String calname = Prefs.getPref(PrefName.CALDAV_CAL);
    CalDavCalendarStore store = connect();
    if (store == null)
        throw new Exception("Failed to connect to CalDav Store");
    String cal_id = createPathResolver().getUserPath(Prefs.getPref(PrefName.CALDAV_USER)) + "/" + calname;
    try {
        store.removeCollection(cal_id);
    } catch (Exception e) {
        log.severe(e.getMessage());
    }
    CalDavCalendarCollection collection = store.addCollection(cal_id, calname, calname, new String[] { "VEVENT", "VTODO" }, null);
    ComponentList<CalendarComponent> clist = calendar.getComponents();
    Iterator<CalendarComponent> it = clist.iterator();
    while (it.hasNext()) {
        CalendarComponent comp = it.next();
        addEvent(collection, comp);
    }
}
Also used : CalendarComponent(net.fortuna.ical4j.model.component.CalendarComponent) CalDavCalendarStore(net.fortuna.ical4j.connector.dav.CalDavCalendarStore) Calendar(net.fortuna.ical4j.model.Calendar) CalDavCalendarCollection(net.fortuna.ical4j.connector.dav.CalDavCalendarCollection)

Example 3 with CalDavCalendarCollection

use of net.fortuna.ical4j.connector.dav.CalDavCalendarCollection in project borg_calendar by mikeberger.

the class CalDav method checkRemoteSync.

/**
 * check remote server to see if sync needed - must not be run on Event thread
 *
 * @throws Exception
 */
public static synchronized boolean checkRemoteSync() throws Exception {
    CalDavCalendarStore store = connect();
    if (store == null)
        throw new Exception("Failed to connect to CalDav Store");
    log.info("SYNC: Get Collection");
    String calname = Prefs.getPref(PrefName.CALDAV_CAL);
    CalDavCalendarCollection collection = getCollection(store, calname);
    String ctag = collection.getProperty(CSDavPropertyName.CTAG, String.class);
    log.info("SYNC: CTAG=" + ctag);
    boolean incoming_changes = true;
    String lastCtag = OptionModel.getReference().getOption(CTAG_OPTION);
    if (lastCtag != null && lastCtag.equals(ctag))
        incoming_changes = false;
    return incoming_changes;
}
Also used : CalDavCalendarStore(net.fortuna.ical4j.connector.dav.CalDavCalendarStore) CalDavCalendarCollection(net.fortuna.ical4j.connector.dav.CalDavCalendarCollection)

Example 4 with CalDavCalendarCollection

use of net.fortuna.ical4j.connector.dav.CalDavCalendarCollection in project axelor-open-suite by axelor.

the class ICalendarService method getCalendar.

public net.fortuna.ical4j.model.Calendar getCalendar(String uid, ICalendar calendar) throws ICalendarException, MalformedURLException {
    net.fortuna.ical4j.model.Calendar cal = null;
    PathResolver RESOLVER = getPathResolver(calendar.getTypeSelect());
    Protocol protocol = getProtocol(calendar.getIsSslConnection());
    URL url = new URL(protocol.getScheme(), calendar.getUrl(), calendar.getPort(), "");
    ICalendarStore store = new ICalendarStore(url, RESOLVER);
    try {
        if (store.connect(calendar.getLogin(), calendar.getPassword())) {
            List<CalDavCalendarCollection> colList = store.getCollections();
            if (!colList.isEmpty()) {
                CalDavCalendarCollection collection = colList.get(0);
                cal = collection.getCalendar(uid);
            }
        } else {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CALENDAR_NOT_VALID));
        }
    } catch (Exception e) {
        throw new ICalendarException(e);
    } finally {
        store.disconnect();
    }
    return cal;
}
Also used : AxelorException(com.axelor.exception.AxelorException) PathResolver(net.fortuna.ical4j.connector.dav.PathResolver) Protocol(org.apache.commons.httpclient.protocol.Protocol) Calendar(net.fortuna.ical4j.model.Calendar) CalDavCalendarCollection(net.fortuna.ical4j.connector.dav.CalDavCalendarCollection) URL(java.net.URL) FailedOperationException(net.fortuna.ical4j.connector.FailedOperationException) URISyntaxException(java.net.URISyntaxException) ObjectStoreException(net.fortuna.ical4j.connector.ObjectStoreException) ParseException(java.text.ParseException) ParserException(net.fortuna.ical4j.data.ParserException) ValidationException(net.fortuna.ical4j.validate.ValidationException) SocketException(java.net.SocketException) AxelorException(com.axelor.exception.AxelorException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) DavException(org.apache.jackrabbit.webdav.DavException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ConstraintViolationException(net.fortuna.ical4j.model.ConstraintViolationException)

Example 5 with CalDavCalendarCollection

use of net.fortuna.ical4j.connector.dav.CalDavCalendarCollection in project axelor-open-suite by axelor.

the class ICalendarService method removeEventFromIcal.

public void removeEventFromIcal(ICalendarEvent event) throws MalformedURLException, ICalendarException {
    if (event.getCalendar() != null && !Strings.isNullOrEmpty(event.getUid())) {
        ICalendar calendar = event.getCalendar();
        PathResolver RESOLVER = getPathResolver(calendar.getTypeSelect());
        Protocol protocol = getProtocol(calendar.getIsSslConnection());
        URL url = new URL(protocol.getScheme(), calendar.getUrl(), calendar.getPort(), "");
        ICalendarStore store = new ICalendarStore(url, RESOLVER);
        try {
            if (store.connect(calendar.getLogin(), getCalendarDecryptPassword(calendar.getPassword()))) {
                List<CalDavCalendarCollection> colList = store.getCollections();
                if (!colList.isEmpty()) {
                    CalDavCalendarCollection collection = colList.get(0);
                    final Map<String, VEvent> remoteEvents = new HashMap<>();
                    for (VEvent item : ICalendarStore.getEvents(collection)) {
                        remoteEvents.put(item.getUid().getValue(), item);
                    }
                    VEvent target = remoteEvents.get(event.getUid());
                    if (target != null)
                        removeCalendar(collection, target.getUid().getValue());
                }
            } else {
                throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CALENDAR_NOT_VALID));
            }
        } catch (Exception e) {
            throw new ICalendarException(e);
        } finally {
            store.disconnect();
        }
    }
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) AxelorException(com.axelor.exception.AxelorException) HashMap(java.util.HashMap) PathResolver(net.fortuna.ical4j.connector.dav.PathResolver) CalDavCalendarCollection(net.fortuna.ical4j.connector.dav.CalDavCalendarCollection) URL(java.net.URL) FailedOperationException(net.fortuna.ical4j.connector.FailedOperationException) URISyntaxException(java.net.URISyntaxException) ObjectStoreException(net.fortuna.ical4j.connector.ObjectStoreException) ParseException(java.text.ParseException) ParserException(net.fortuna.ical4j.data.ParserException) ValidationException(net.fortuna.ical4j.validate.ValidationException) SocketException(java.net.SocketException) AxelorException(com.axelor.exception.AxelorException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) DavException(org.apache.jackrabbit.webdav.DavException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ConstraintViolationException(net.fortuna.ical4j.model.ConstraintViolationException) ICalendar(com.axelor.apps.base.db.ICalendar) Protocol(org.apache.commons.httpclient.protocol.Protocol)

Aggregations

CalDavCalendarCollection (net.fortuna.ical4j.connector.dav.CalDavCalendarCollection)7 CalDavCalendarStore (net.fortuna.ical4j.connector.dav.CalDavCalendarStore)4 AxelorException (com.axelor.exception.AxelorException)3 IOException (java.io.IOException)3 MalformedURLException (java.net.MalformedURLException)3 SocketException (java.net.SocketException)3 URISyntaxException (java.net.URISyntaxException)3 URL (java.net.URL)3 ParseException (java.text.ParseException)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 FailedOperationException (net.fortuna.ical4j.connector.FailedOperationException)3 ObjectStoreException (net.fortuna.ical4j.connector.ObjectStoreException)3 PathResolver (net.fortuna.ical4j.connector.dav.PathResolver)3 ParserException (net.fortuna.ical4j.data.ParserException)3 Calendar (net.fortuna.ical4j.model.Calendar)3 ConstraintViolationException (net.fortuna.ical4j.model.ConstraintViolationException)3 ValidationException (net.fortuna.ical4j.validate.ValidationException)3 Protocol (org.apache.commons.httpclient.protocol.Protocol)3 DavException (org.apache.jackrabbit.webdav.DavException)3 ICalendar (com.axelor.apps.base.db.ICalendar)1