Search in sources :

Example 1 with ParserException

use of net.fortuna.ical4j.data.ParserException in project openhab1-addons by openhab.

the class EventReloaderJob method execute.

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    final String config = context.getJobDetail().getJobDataMap().getString(KEY_CONFIG);
    CalendarRuntime eventRuntime = EventStorage.getInstance().getEventCache().get(config);
    log.debug("running EventReloaderJob for config : {}", config);
    // reload cached events (if necessary)
    if (!cachedEventsLoaded.containsKey(config)) {
        try {
            log.debug("reload cached events for config: {}", eventRuntime.getConfig().getKey());
            for (File fileCalendarKeys : new File(CalDavLoaderImpl.CACHE_PATH).listFiles()) {
                if (!eventRuntime.getConfig().getKey().equals(Util.getFilename(fileCalendarKeys.getName()))) {
                    log.trace("not our config : {}", Util.getFilename(fileCalendarKeys.getName()));
                    continue;
                }
                log.trace("found our config : {}", Util.getFilename(fileCalendarKeys.getName()));
                final Collection<File> icsFiles = FileUtils.listFiles(fileCalendarKeys, new String[] { "ics" }, false);
                for (File icsFile : icsFiles) {
                    try {
                        FileInputStream fis = new FileInputStream(icsFile);
                        log.debug("loading events from file : {}", icsFile);
                        loadEvents(Util.getFilename(icsFile.getAbsolutePath()), new org.joda.time.DateTime(icsFile.lastModified()), fis, eventRuntime.getConfig(), new ArrayList<String>(), true);
                    } catch (IOException e) {
                        log.error("cannot load events for file: " + icsFile, e);
                    } catch (ParserException e) {
                        log.error("cannot load events for file: " + icsFile, e);
                    }
                }
                break;
            }
        } catch (Throwable e) {
            log.error("cannot load events", e);
        } finally {
            cachedEventsLoaded.put(config, true);
        }
    }
    try {
        log.debug("loading events for config: " + config);
        List<String> oldEventIds = new ArrayList<String>();
        for (EventContainer eventContainer : eventRuntime.getEventMap().values()) {
            oldEventIds.add(eventContainer.getFilename());
            log.debug("old eventcontainer -- id : {} -- filename : {} -- calcuntil : {} -- lastchanged : {} -- ishistoric : {}", eventContainer.getEventId(), eventContainer.getFilename(), eventContainer.getCalculatedUntil(), eventContainer.getLastChanged(), eventContainer.isHistoricEvent());
            if (log.isDebugEnabled()) {
                for (int i = 0; i < eventContainer.getEventList().size(); i++) {
                    CalDavEvent elem = eventContainer.getEventList().get(i);
                    log.debug("old eventlist contient l'evenement : {} -- deb : {} -- fin : {} -- lastchang {}", elem.getName(), elem.getStart(), elem.getEnd(), elem.getLastChanged());
                }
            }
        }
        loadEvents(eventRuntime, oldEventIds);
        // stop all events in oldMap
        removeDeletedEvents(config, oldEventIds);
        for (EventNotifier notifier : CalDavLoaderImpl.instance.getEventListenerList()) {
            try {
                notifier.calendarReloaded(config);
            } catch (Exception e) {
                log.error("error while invoking listener", e);
            }
        }
        // print All scheduled jobs :
        if (log.isDebugEnabled()) {
            log.debug("jobs scheduled : ");
            Scheduler scheduler = CalDavLoaderImpl.instance.getScheduler();
            for (String groupName : CalDavLoaderImpl.instance.getScheduler().getJobGroupNames()) {
                for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName))) {
                    String jobName = jobKey.getName();
                    String jobGroup = jobKey.getGroup();
                    // get job's trigger
                    List<Trigger> triggers = (List<Trigger>) scheduler.getTriggersOfJob(jobKey);
                    Date nextFireTime = triggers.get(0).getNextFireTime();
                    log.debug("[job] : {} - [groupName] : {} - {}", jobName, jobGroup, nextFireTime);
                }
            }
        }
    } catch (SardineException e) {
        log.error("error while loading calendar entries: {} ({} - {} )", e.getMessage(), e.getStatusCode(), e.getResponsePhrase(), e);
        throw new JobExecutionException("error while loading calendar entries", e, false);
    } catch (Exception e) {
        log.error("error while loading calendar entries: {}", e.getMessage(), e);
        throw new JobExecutionException("error while loading calendar entries", e, false);
    }
}
Also used : Scheduler(org.quartz.Scheduler) ArrayList(java.util.ArrayList) JobKey(org.quartz.JobKey) SardineException(com.github.sardine.impl.SardineException) Trigger(org.quartz.Trigger) JobExecutionException(org.quartz.JobExecutionException) EventNotifier(org.openhab.io.caldav.EventNotifier) PropertyList(net.fortuna.ical4j.model.PropertyList) List(java.util.List) ArrayList(java.util.ArrayList) ComponentList(net.fortuna.ical4j.model.ComponentList) PeriodList(net.fortuna.ical4j.model.PeriodList) ParserException(net.fortuna.ical4j.data.ParserException) EventContainer(org.openhab.io.caldav.internal.EventStorage.EventContainer) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) ParserException(net.fortuna.ical4j.data.ParserException) JobExecutionException(org.quartz.JobExecutionException) SchedulerException(org.quartz.SchedulerException) IOException(java.io.IOException) SardineException(com.github.sardine.impl.SardineException) Date(java.util.Date) CalDavEvent(org.openhab.io.caldav.CalDavEvent) CalendarRuntime(org.openhab.io.caldav.internal.EventStorage.CalendarRuntime) CalendarRuntime(org.openhab.io.caldav.internal.EventStorage.CalendarRuntime) File(java.io.File)

Example 2 with ParserException

use of net.fortuna.ical4j.data.ParserException in project LAMSADE-tools by LAntoine.

the class Tester method main.

public static void main(String[] args) throws SQLException {
    System.setProperty("SWT_GTK3", "0");
    Display display = new Display();
    Shell shell = new Shell(display);
    // shell.setSize(300, 300);
    shell.setText("Conference List");
    GridLayout gridLayout = new GridLayout();
    shell.setLayout(gridLayout);
    shell.setLocation(400, 200);
    shell.layout(true, true);
    final Point newSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    shell.setSize(new Point(888, 661));
    /*
		 * Initialize Group conferencesInfos which will include : -The Grid data
		 * which will display conferences
		 *
		 * -The fields that will allow the user to add a new conference in the
		 * database
		 */
    Group grpUserDetails = new Group(shell, SWT.NONE);
    GridData gd_grpUserDetails = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_grpUserDetails.widthHint = 848;
    gd_grpUserDetails.heightHint = 155;
    grpUserDetails.setLayoutData(gd_grpUserDetails);
    grpUserDetails.setText("User Details");
    Label lblFirstname = new Label(grpUserDetails, SWT.NONE);
    lblFirstname.setBounds(10, 26, 70, 15);
    lblFirstname.setText("First Name");
    Label lblNewLabel_1 = new Label(grpUserDetails, SWT.NONE);
    lblNewLabel_1.setBounds(10, 53, 55, 15);
    lblNewLabel_1.setText("Last Name");
    txt_firstname = new Text(grpUserDetails, SWT.BORDER);
    txt_firstname.setBounds(86, 23, 98, 21);
    txt_lastname = new Text(grpUserDetails, SWT.BORDER);
    txt_lastname.setBounds(86, 50, 98, 21);
    /*
		 * Handle the User Info's Search Throws exception if firstname or
		 * lastname is wrong
		 */
    Button btn_searchInfo = new Button(grpUserDetails, SWT.NONE);
    btn_searchInfo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            try {
                UserDetails user = GetInfosFromYearbook.getUserDetails(txt_lastname.getText(), txt_firstname.getText());
                txt_function.setText(user.getFunction());
                txt_number.setText(user.getNumber());
                txt_email.setText(user.getEmail());
                txt_group.setText(user.getGroup());
                txt_fax.setText(user.getFax());
                txt_office.setText(user.getOffice());
                txt_city_ud.setText(user.getCity());
                txt_country_ud.setText(user.getCountry());
            } catch (@SuppressWarnings("unused") Exception e) {
                MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
                mb.setText("Error");
                mb.setMessage("Please verify firstname and lastname");
                mb.open();
            }
        }
    });
    btn_searchInfo.setBounds(10, 87, 114, 25);
    btn_searchInfo.setText("Search My Infos");
    Label lbl_function = new Label(grpUserDetails, SWT.NONE);
    lbl_function.setBounds(224, 26, 55, 15);
    lbl_function.setText("Function");
    Label lbl_number = new Label(grpUserDetails, SWT.NONE);
    lbl_number.setBounds(224, 56, 55, 15);
    lbl_number.setText("Phone");
    Label lbl_email = new Label(grpUserDetails, SWT.NONE);
    lbl_email.setBounds(224, 92, 55, 15);
    lbl_email.setText("E-mail");
    Label lbl_group = new Label(grpUserDetails, SWT.NONE);
    lbl_group.setBounds(224, 124, 55, 15);
    lbl_group.setText("Group");
    txt_function = new Text(grpUserDetails, SWT.BORDER);
    txt_function.setBounds(285, 20, 219, 21);
    txt_number = new Text(grpUserDetails, SWT.BORDER);
    txt_number.setBounds(285, 53, 219, 21);
    txt_email = new Text(grpUserDetails, SWT.BORDER);
    txt_email.setBounds(285, 87, 219, 21);
    txt_group = new Text(grpUserDetails, SWT.BORDER);
    txt_group.setBounds(285, 121, 219, 21);
    Label lbl_fax = new Label(grpUserDetails, SWT.NONE);
    lbl_fax.setText("Fax");
    lbl_fax.setBounds(535, 26, 55, 15);
    Label lbl_office = new Label(grpUserDetails, SWT.NONE);
    lbl_office.setText("Office");
    lbl_office.setBounds(535, 59, 55, 15);
    Label lbl_city = new Label(grpUserDetails, SWT.NONE);
    lbl_city.setText("City");
    lbl_city.setBounds(535, 92, 55, 15);
    Label lbl_country = new Label(grpUserDetails, SWT.NONE);
    lbl_country.setText("Country");
    lbl_country.setBounds(535, 124, 55, 15);
    txt_fax = new Text(grpUserDetails, SWT.BORDER);
    txt_fax.setBounds(596, 23, 219, 21);
    txt_office = new Text(grpUserDetails, SWT.BORDER);
    txt_office.setBounds(596, 56, 219, 21);
    txt_city_ud = new Text(grpUserDetails, SWT.BORDER);
    txt_city_ud.setBounds(596, 89, 219, 21);
    txt_country_ud = new Text(grpUserDetails, SWT.BORDER);
    txt_country_ud.setBounds(596, 121, 219, 21);
    Group grp_conferencesInfos = new Group(shell, SWT.NONE);
    GridData gd_conferencesInfos = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_conferencesInfos.heightHint = 237;
    gd_conferencesInfos.widthHint = 854;
    grp_conferencesInfos.setLayoutData(gd_conferencesInfos);
    grp_conferencesInfos.setText("Conferences");
    Table table = new Table(grp_conferencesInfos, SWT.V_SCROLL);
    table.setBounds(165, 16, 502, 134);
    table.setHeaderVisible(true);
    fillConferenceTable(table);
    Button btn_addNewConf = new Button(grp_conferencesInfos, SWT.NONE);
    btn_addNewConf.setBounds(165, 156, 149, 25);
    btn_addNewConf.setText("Create conference");
    Label lblTitle = new Label(grp_conferencesInfos, SWT.NONE);
    lblTitle.setAlignment(SWT.RIGHT);
    lblTitle.setBounds(25, 16, 50, 15);
    lblTitle.setText("Title");
    Text txt_title = new Text(grp_conferencesInfos, SWT.BORDER);
    txt_title.setBounds(81, 15, 78, 21);
    Label lblUrl = new Label(grp_conferencesInfos, SWT.NONE);
    lblUrl.setAlignment(SWT.RIGHT);
    lblUrl.setText("URL");
    lblUrl.setBounds(25, 45, 50, 15);
    Text txt_url = new Text(grp_conferencesInfos, SWT.BORDER);
    txt_url.setBounds(81, 42, 78, 21);
    Label lblStartDate = new Label(grp_conferencesInfos, SWT.NONE);
    lblStartDate.setAlignment(SWT.RIGHT);
    lblStartDate.setText("Start Date");
    lblStartDate.setBounds(10, 72, 65, 15);
    Text txt_startDate = new Text(grp_conferencesInfos, SWT.BORDER);
    txt_startDate.setBounds(81, 69, 78, 21);
    Label lblEndDate = new Label(grp_conferencesInfos, SWT.NONE);
    lblEndDate.setAlignment(SWT.RIGHT);
    lblEndDate.setText("End Date");
    lblEndDate.setBounds(10, 99, 65, 15);
    Text txt_endDate = new Text(grp_conferencesInfos, SWT.BORDER);
    txt_endDate.setBounds(81, 96, 78, 21);
    Label lblFee = new Label(grp_conferencesInfos, SWT.NONE);
    lblFee.setText("Fee");
    lblFee.setBounds(42, 126, 33, 15);
    Text txt_fee = new Text(grp_conferencesInfos, SWT.BORDER);
    txt_fee.setBounds(81, 123, 78, 21);
    // add news fields
    /*
		 * Label lblCity= new Label(grp_conferencesInfos, SWT.NONE);
		 * lblCity.setAlignment(SWT.RIGHT); lblCity.setBounds(25, 38, 50, 15);
		 * lblCity.setText("City"); Text txt_city = new
		 * Text(grp_conferencesInfos, SWT.BORDER); txt_city.setBounds(81, 35,
		 * 78, 21);
		 */
    Label lblCity = new Label(grp_conferencesInfos, SWT.NONE);
    lblCity.setAlignment(SWT.RIGHT);
    lblCity.setBounds(25, 153, 50, 15);
    lblCity.setText("City");
    Text txt_city = new Text(grp_conferencesInfos, SWT.BORDER);
    txt_city.setBounds(81, 150, 78, 21);
    Label lbladdress = new Label(grp_conferencesInfos, SWT.NONE);
    lbladdress.setAlignment(SWT.RIGHT);
    lbladdress.setBounds(25, 180, 50, 15);
    lbladdress.setText("Address");
    Text txt_address = new Text(grp_conferencesInfos, SWT.BORDER);
    txt_address.setBounds(81, 177, 78, 21);
    // Create new Conference object, assign it values from
    // selection, then pass it function to export to desktop
    // public Conference(int id, String title, String url, LocalDate
    // start_date, LocalDate end_date, double entry_fee)
    Button btnExportEvent = new Button(grp_conferencesInfos, SWT.NONE);
    btnExportEvent.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/M/yyyy");
            TableItem[] ti = table.getSelection();
            if (ti.length == 0) {
            // Put somewhere that an event should be selected
            } else {
                Conference conf = new Conference(ti[0].getText(0), ti[0].getText(1), LocalDate.parse(ti[0].getText(2), formatter), LocalDate.parse(ti[0].getText(3), formatter), Double.parseDouble(ti[0].getText(4)), ti[0].getText(5), ti[0].getText(6));
                try {
                    FileDialog dialog = new FileDialog(shell, SWT.SAVE);
                    dialog.setFilterNames(new String[] { "Calendar Files", "All Files (*.*)" });
                    // Windows
                    dialog.setFilterExtensions(new String[] { "*.ics", "*.*" });
                    switch(Util.getOS()) {
                        case WINDOWS:
                            dialog.setFilterPath("c:\\");
                            break;
                        case LINUX:
                            dialog.setFilterPath("/");
                            break;
                        case MAC:
                            dialog.setFilterPath("/");
                            break;
                        case SOLARIS:
                            dialog.setFilterPath("/");
                            break;
                        default:
                            dialog.setFilterPath("/");
                    }
                    dialog.setFileName("conference.ics");
                    conf.generateCalendarFile(dialog.open());
                } catch (IOException | ValidationException | ParserException e2) {
                    e2.printStackTrace();
                }
            }
        }
    });
    btnExportEvent.setBounds(320, 154, 104, 28);
    btnExportEvent.setText("Export Event");
    /*
		 * Behavior of a click on the add new conference button
		 */
    btn_addNewConf.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            System.out.println("Appui sur le bouton");
            if (!txt_title.getText().isEmpty() && !txt_url.getText().isEmpty() && !txt_startDate.getText().isEmpty() && !txt_startDate.getText().isEmpty() && !txt_endDate.getText().isEmpty() && !txt_fee.getText().isEmpty()) {
                try {
                    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
                    LocalDate startDate = LocalDate.parse(txt_startDate.getText(), formatter);
                    LocalDate endDate = LocalDate.parse(txt_endDate.getText(), formatter);
                    Conference conf = new Conference(txt_title.getText(), txt_url.getText(), startDate, endDate, Double.parseDouble(txt_fee.getText()), txt_city.getText(), txt_address.getText());
                    ConferenceDatabase.insertInDatabase(conf);
                    /*
						 * Reload the conference table
						 */
                    table.removeAll();
                    fillConferenceTable(table);
                } catch (DateTimeParseException e1) {
                    MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
                    mb.setText("Date format error");
                    mb.setMessage("Please fill the dates in the following format : dd/MM/YYYY");
                    mb.open();
                } catch (SQLException e2) {
                    throw new IllegalStateException(e2);
                }
            } else {
                MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
                mb.setText("Information missing");
                mb.setMessage("Please fill in the information regarding the conference");
                mb.open();
            }
        }
    });
    /*
		 * This group will help the user to see his itinerary into the browser
		 */
    Group grp_map = new Group(shell, SWT.NONE);
    grp_map.setText("Visualize your travel");
    GridData gd_map = new GridData(SWT.LEFT, SWT.CENTER, false, true, 1, 1);
    gd_map.heightHint = 85;
    gd_map.widthHint = 860;
    grp_map.setLayoutData(gd_map);
    Text departure = new Text(grp_map, SWT.BORDER);
    departure.setLocation(101, 22);
    departure.setSize(196, 21);
    Text arrival = new Text(grp_map, SWT.BORDER);
    arrival.setLocation(101, 51);
    arrival.setSize(196, 21);
    Button btnItinerary = new Button(grp_map, SWT.NONE);
    btnItinerary.setText("Validate");
    btnItinerary.setBounds(303, 49, 68, 25);
    Label lblDeparture = new Label(grp_map, SWT.NONE);
    lblDeparture.setAlignment(SWT.RIGHT);
    lblDeparture.setBounds(10, 25, 73, 15);
    lblDeparture.setText("Departure");
    Label lblArrival = new Label(grp_map, SWT.NONE);
    lblArrival.setAlignment(SWT.RIGHT);
    lblArrival.setBounds(10, 54, 73, 15);
    lblArrival.setText("Arrival");
    /*
		 * Behavior of the btnItinerary : Takes the addresses entered in
		 * departure and arrival Texts and call the ItineraryMap class to open
		 * the itinerary into the browser
		 */
    btnItinerary.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            System.out.println("Appui sur le bouton");
            if (!departure.getText().isEmpty() && !arrival.getText().isEmpty()) {
                try {
                    AddressInfos dep = new AddressInfos(departure.getText());
                    AddressInfos arr = new AddressInfos(arrival.getText());
                    // ItineraryMap itinerary = new
                    // ItineraryMap(dep.getLongitude(),
                    // dep.getLatitude(),arr.getLongitude(),
                    // arr.getLatitude());
                    GoogleItineraryMap itinerary = new GoogleItineraryMap(departure.getText(), arrival.getText());
                    String url = itinerary.setMapUrl();
                    System.out.println(url);
                    itinerary.openMapUrl(url);
                } catch (IllegalArgumentException e) {
                    LOGGER.error("Error : ", e);
                }
            } else {
                MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
                mb.setText("Infromation missing");
                mb.setMessage("Please fill in the departure and arrival fields");
                mb.open();
            }
        }
    });
    arrival.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            System.out.println("nouvelle valeur = " + ((Text) e.widget).getText());
        }
    });
    departure.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            System.out.println("nouvelle valeur = " + ((Text) e.widget).getText());
        }
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}
Also used : Group(org.eclipse.swt.widgets.Group) AddressInfos(com.github.lantoine.lamsadetools.map.AddressInfos) ModifyListener(org.eclipse.swt.events.ModifyListener) SQLException(java.sql.SQLException) Label(org.eclipse.swt.widgets.Label) Conference(com.github.lantoine.lamsadetools.conferences.Conference) LocalDate(java.time.LocalDate) Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) GoogleItineraryMap(com.github.lantoine.lamsadetools.map.GoogleItineraryMap) ModifyEvent(org.eclipse.swt.events.ModifyEvent) UserDetails(com.github.lantoine.lamsadetools.setCoordinates.UserDetails) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Table(org.eclipse.swt.widgets.Table) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) ValidationException(net.fortuna.ical4j.model.ValidationException) SQLException(java.sql.SQLException) ParserException(net.fortuna.ical4j.data.ParserException) IOException(java.io.IOException) DateTimeParseException(java.time.format.DateTimeParseException) MessageBox(org.eclipse.swt.widgets.MessageBox) DateTimeParseException(java.time.format.DateTimeParseException) GridData(org.eclipse.swt.layout.GridData) DateTimeFormatter(java.time.format.DateTimeFormatter) FileDialog(org.eclipse.swt.widgets.FileDialog) Display(org.eclipse.swt.widgets.Display)

Example 3 with ParserException

use of net.fortuna.ical4j.data.ParserException in project bw-calendar-engine by Bedework.

the class IcalUtil method parseVpollCandidates.

/**
 * @param poll the poll entity
 * @return Parsed components.
 * @throws Throwable
 */
public static Map<Integer, Component> parseVpollCandidates(final BwEvent poll) throws Throwable {
    final StringBuilder sb = new StringBuilder();
    sb.append("BEGIN:VCALENDAR\n");
    sb.append("PRODID://Bedework.org//BedeWork V3.9//EN\n");
    sb.append("VERSION:2.0\n");
    if (!Util.isEmpty(poll.getPollItems())) {
        for (final String s : poll.getPollItems()) {
            sb.append(s);
        }
    }
    sb.append("END:VCALENDAR\n");
    try {
        final StringReader sr = new StringReader(sb.toString());
        final Icalendar ic = new Icalendar();
        final CalendarBuilder bldr = new CalendarBuilder(new CalendarParserImpl(), ic);
        final UnfoldingReader ufrdr = new UnfoldingReader(sr, true);
        final Calendar ical = bldr.build(ufrdr);
        final Map<Integer, Component> comps = new HashMap<>();
        for (final Object o : ical.getComponents()) {
            final Component comp = (Component) o;
            final PollItemId pid = (PollItemId) comp.getProperty(Property.POLL_ITEM_ID);
            if (pid == null) {
                continue;
            }
            comps.put(pid.getPollitemid(), comp);
        }
        return comps;
    } catch (final ParserException pe) {
        throw new IcalMalformedException(pe.getMessage());
    } catch (final Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : ParserException(net.fortuna.ical4j.data.ParserException) CalendarParserImpl(net.fortuna.ical4j.data.CalendarParserImpl) HashMap(java.util.HashMap) UnfoldingReader(net.fortuna.ical4j.data.UnfoldingReader) Calendar(net.fortuna.ical4j.model.Calendar) PollItemId(net.fortuna.ical4j.model.property.PollItemId) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) StringReader(java.io.StringReader) CalendarComponent(net.fortuna.ical4j.model.component.CalendarComponent) StartEndComponent(org.bedework.calfacade.base.StartEndComponent) Component(net.fortuna.ical4j.model.Component)

Example 4 with ParserException

use of net.fortuna.ical4j.data.ParserException in project opencast by opencast.

the class SchedulerServiceImplTest method testEventManagement.

@Test
public void testEventManagement() throws Exception {
    MediaPackage mediaPackage = generateEvent(Opt.<String>none());
    DublinCoreCatalog event = generateEvent("testdevice", new Date(System.currentTimeMillis() - 2000), new Date(System.currentTimeMillis() + 60000));
    event.set(PROPERTY_TITLE, "Demotitle");
    event.add(PROPERTY_CREATOR, "creator2");
    String catalogId = addDublinCore(Opt.<String>none(), mediaPackage, event);
    Map<String, String> caProperties = generateCaptureAgentMetadata("testdevice");
    schedSvc.addEvent(new Date(System.currentTimeMillis() - 2000), new Date(System.currentTimeMillis() + 60000), "testdevice", Collections.<String>emptySet(), mediaPackage, wfProperties, caProperties, Opt.<Boolean>none(), Opt.<String>none(), SchedulerService.ORIGIN);
    // test iCalender export
    CalendarBuilder calBuilder = new CalendarBuilder();
    Calendar cal;
    try {
        String icalString = schedSvc.getCalendar(Opt.<String>none(), Opt.<String>none(), Opt.<Date>none());
        cal = calBuilder.build(IOUtils.toInputStream(icalString, "UTF-8"));
        ComponentList vevents = cal.getComponents(VEVENT);
        for (int i = 0; i < vevents.size(); i++) {
            PropertyList attachments = ((VEvent) vevents.get(i)).getProperties(Property.ATTACH);
            for (int j = 0; j < attachments.size(); j++) {
                String attached = ((Property) attachments.get(j)).getValue();
                String filename = ((Property) attachments.get(j)).getParameter("X-APPLE-FILENAME").getValue();
                attached = new String(Base64.decodeBase64(attached));
                if ("org.opencastproject.capture.agent.properties".equals(filename)) {
                    Assert.assertTrue(attached.contains("capture.device.id=testdevice"));
                }
                if ("episode.xml".equals(filename)) {
                    Assert.assertTrue(attached.contains("Demotitle"));
                }
            }
        }
    } catch (IOException e) {
        Assert.fail(e.getMessage());
    } catch (ParserException e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
    // test for upcoming events (it should not be in there).
    List<MediaPackage> upcoming = schedSvc.search(Opt.<String>none(), Opt.some(new Date(System.currentTimeMillis())), Opt.<Date>none(), Opt.<Date>none(), Opt.<Date>none());
    Assert.assertTrue(upcoming.isEmpty());
    List<MediaPackage> all = schedSvc.search(Opt.<String>none(), Opt.<Date>none(), Opt.<Date>none(), Opt.<Date>none(), Opt.<Date>none());
    assertEquals(1, all.size());
    all = schedSvc.search(Opt.some("somedevice"), Opt.<Date>none(), Opt.<Date>none(), Opt.<Date>none(), Opt.<Date>none());
    Assert.assertTrue(all.isEmpty());
    // update event
    event.set(PROPERTY_TEMPORAL, EncodingSchemeUtils.encodePeriod(new DCMIPeriod(new Date(System.currentTimeMillis() + 180000), new Date(System.currentTimeMillis() + 600000)), Precision.Second));
    addDublinCore(Opt.some(catalogId), mediaPackage, event);
    schedSvc.updateEvent(mediaPackage.getIdentifier().compact(), Opt.some(new Date(System.currentTimeMillis() + 180000)), Opt.some(new Date(System.currentTimeMillis() + 600000)), Opt.<String>none(), Opt.<Set<String>>none(), Opt.some(mediaPackage), Opt.some(wfPropertiesUpdated), Opt.<Map<String, String>>none(), Opt.<Opt<Boolean>>none(), SchedulerService.ORIGIN);
    // test for upcoming events (now it should be there)
    upcoming = schedSvc.search(Opt.<String>none(), Opt.some(new Date(System.currentTimeMillis())), Opt.<Date>none(), Opt.<Date>none(), Opt.<Date>none());
    assertEquals(1, upcoming.size());
    // delete event
    schedSvc.removeEvent(mediaPackage.getIdentifier().compact());
    try {
        schedSvc.getMediaPackage(mediaPackage.getIdentifier().compact());
        Assert.fail();
    } catch (NotFoundException e) {
        Assert.assertNotNull(e);
    }
    upcoming = schedSvc.search(Opt.<String>none(), Opt.<Date>none(), Opt.<Date>none(), Opt.<Date>none(), Opt.<Date>none());
    assertEquals(0, upcoming.size());
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) ParserException(net.fortuna.ical4j.data.ParserException) CalendarBuilder(net.fortuna.ical4j.data.CalendarBuilder) Calendar(net.fortuna.ical4j.model.Calendar) DCMIPeriod(org.opencastproject.metadata.dublincore.DCMIPeriod) NotFoundException(org.opencastproject.util.NotFoundException) ComponentList(net.fortuna.ical4j.model.ComponentList) IOException(java.io.IOException) Date(java.util.Date) PropertyList(net.fortuna.ical4j.model.PropertyList) MediaPackage(org.opencastproject.mediapackage.MediaPackage) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Property(net.fortuna.ical4j.model.Property) Test(org.junit.Test)

Example 5 with ParserException

use of net.fortuna.ical4j.data.ParserException in project OpenOLAT by OpenOLAT.

the class ICalServlet method getOutlookVTimeZone.

/**
 * Load the VTimeZone for Outlook. ical4j use a static map to reuse the TimeZone objects, we need to load
 * and save our specialized TimeZone in a separate map.
 */
private VTimeZone getOutlookVTimeZone(final String id) throws IOException, ParserException {
    return outlookVTimeZones.computeIfAbsent(id, (timeZoneId) -> {
        try {
            URL resource = ResourceLoader.getResource("zoneinfo-outlook/" + id + ".ics");
            CalendarBuilder builder = new CalendarBuilder();
            Calendar calendar = builder.build(resource.openStream());
            VTimeZone vTimeZone = (VTimeZone) calendar.getComponent(Component.VTIMEZONE);
            return vTimeZone;
        } catch (Exception e) {
            log.error("", e);
            return null;
        }
    });
}
Also used : CalendarBuilder(net.fortuna.ical4j.data.CalendarBuilder) Calendar(net.fortuna.ical4j.model.Calendar) VTimeZone(net.fortuna.ical4j.model.component.VTimeZone) URL(java.net.URL) ValidationException(net.fortuna.ical4j.model.ValidationException) ServletException(javax.servlet.ServletException) URISyntaxException(java.net.URISyntaxException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) ParserException(net.fortuna.ical4j.data.ParserException) IOException(java.io.IOException)

Aggregations

ParserException (net.fortuna.ical4j.data.ParserException)13 IOException (java.io.IOException)8 Calendar (net.fortuna.ical4j.model.Calendar)6 CalendarBuilder (net.fortuna.ical4j.data.CalendarBuilder)4 ValidationException (net.fortuna.ical4j.model.ValidationException)4 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 URISyntaxException (java.net.URISyntaxException)3 URL (java.net.URL)3 VTimeZone (net.fortuna.ical4j.model.component.VTimeZone)3 Conference (com.github.lantoine.lamsadetools.conferences.Conference)2 GoogleItineraryMap (com.github.lantoine.lamsadetools.map.GoogleItineraryMap)2 UserDetails (com.github.lantoine.lamsadetools.setCoordinates.UserDetails)2 SardineException (com.github.sardine.impl.SardineException)2 StringReader (java.io.StringReader)2 SQLException (java.sql.SQLException)2 LocalDate (java.time.LocalDate)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 DateTimeParseException (java.time.format.DateTimeParseException)2 Date (java.util.Date)2