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");
}
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);
}
}
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;
}
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;
}
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();
}
}
}
Aggregations