0

I created a client that is getting calendar data (VEvents) from Yahoo. Now I need to be able to update existing or create new event and 'publish' it, to be visible from Yahoo calendar.

Can this be done with ical4j or I need to find some other way to do it?

Djordje Ivanovic
  • 4,151
  • 4
  • 27
  • 49
  • This question is too generic and provides far too little detail. When trying to use ical4j, what problems did you encounter? – hnh Feb 20 '17 at 12:23
  • The problem is that I cant find example how to do this, so I'm not sure if this is possible, which I pointed out in question. – Djordje Ivanovic Feb 20 '17 at 12:40
  • I can update and delete events, but in CalDAVCollection, method called add always creates a new calendar. I need to add the event to the existing calendar. Dont see this option. – Djordje Ivanovic Feb 20 '17 at 15:07

1 Answers1

1

Ok, I found a way of doing this. The problem was that for CalDavCollection, you can't actually add event directly, you need to add it as a Calendar. The code that is working:

public void addEvent(VEvent event, VTimeZone timezone){
                    try {
                        Calendar calendar = new Calendar();
                        calendar.getProperties().add(new ProdId(prodId));
                        calendar.getProperties().add(Version.VERSION_2_0);
                        calendar.getProperties().add(CalScale.GREGORIAN);
                        calendar.getComponents().add(event);
                        collection.add(httpClient, calendar);
                    } catch (CalDAV4JException e) {
                        e.printStackTrace();
                    }

    }

The 'prodId' in line

calendar.getProperties().add(new ProdId(prodId));

is the prodId of the Calendar provider (in my case it is PRODID://Yahoo//Calendar//EN)

The collection is the instance of the CalDavCollecion, that is related to specific Calendar, so just adding calendar with new event inside will add it to the server to the correct calendar.

Djordje Ivanovic
  • 4,151
  • 4
  • 27
  • 49
  • 1
    The ProdId is *not* the product id of the target calendar. It needs to be the product id of the application producing the iCalendar. Checkout [RFC 5545 PRODID](https://tools.ietf.org/html/rfc5545#section-3.7.3). You can check the RFC on what fields are required and which are not. – hnh Feb 21 '17 at 12:23
  • You are probably right but I took it like: prodId = calendar.getProductId().getValue(); where the calendar is one of the calendars from collection. I have couple of calendars on yahoo, and the only one that was updated was the one I needed. – Djordje Ivanovic Feb 21 '17 at 12:53
  • 1
    There is no probability in this, this is specified in the RFC, please fix your code. The PRODID is used to check what software generated an iCalendar entity (e.g. to workaround bugs), and in this case it is yours. You cannot just reuse a PRODID you don't own! – hnh Feb 21 '17 at 13:34
  • I will fix it, but not sure how to do it. Can you please give me the valid example how to add event to the existing calendar using CalDavCollecion without using this prodId? And of course, thanks for your efforts. – Djordje Ivanovic Feb 21 '17 at 14:27