net.fortuna.ical4j.validate.ValidationException Java Examples

The following examples show how to use net.fortuna.ical4j.validate.ValidationException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ICalendarService.java    From axelor-open-suite with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Export the calendar to the given output writer.
 *
 * @param calendar the source {@link ICalendar}
 * @param writer the output writer
 * @throws IOException
 * @throws ParseException
 * @throws ValidationException
 */
public void export(ICalendar calendar, Writer writer)
    throws IOException, ParseException, ValidationException {
  Preconditions.checkNotNull(calendar, "calendar can't be null");
  Preconditions.checkNotNull(writer, "writer can't be null");
  Preconditions.checkNotNull(getICalendarEvents(calendar), "can't export empty calendar");

  Calendar cal = newCalendar();
  cal.getProperties().add(new XProperty(X_WR_CALNAME, calendar.getName()));

  for (ICalendarEvent item : getICalendarEvents(calendar)) {
    VEvent event = createVEvent(item);
    cal.getComponents().add(event);
  }

  CalendarOutputter outputter = new CalendarOutputter();
  outputter.output(cal, writer);
}
 
Example #2
Source File: ContextServiceExtensionsAdviceTest.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * If the item has no event stamps, the event extension data is not created
 * because is not used. the processing continues.
 * @throws IOException 
 * @throws ValidationException 
 */
@Test
public void createEventNotCreatedIfNoEventStamps() throws IOException, ValidationException{
    //advice setup
    createProxyServiceWithExpectedAdviceExecution();      
    addNoCallExpectedOnHandlers();
 
    
    //test data        
    User user = testHelper.makeDummyUser("user1", "password");

    CollectionItem rootCollection = contentDao.createRootItem(user);
    
    //call service
    ContentItem contentItem = testHelper.makeDummyContent(user);
    contentItem.addStamp(new HibTaskStamp());
    
    Set<ContentItem> contentItems = new HashSet<ContentItem>();
    contentItems.add(contentItem);
    //test(fails if getEventData method is called)
    proxyService.createContentItems(rootCollection, contentItems);     
    
    proxyService.updateContent(contentItem);
    
    proxyService.removeContent(contentItem);
}
 
Example #3
Source File: ContextServiceExtensionsAdviceTest.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * If the item has no stamps, the event extension data is not created
 * because is not used. the processing continues.
 * @throws IOException 
 * @throws ValidationException 
 */
@Test
public void createEventNotCreatedIfNoStamps() throws IOException, ValidationException{
    createProxyServiceWithoutExpectedAdviceExecution();
    addNoCallExpectedOnHandlers();
 
    //test data        
    User user = testHelper.makeDummyUser("user1", "password");

    CollectionItem rootCollection = contentDao.createRootItem(user);
    
    //call service
    ContentItem contentItem = testHelper.makeDummyContent(user);
    Set<ContentItem> contentItems = new HashSet<ContentItem>();
    contentItems.add(contentItem);
    
    //test(fails if getEventData method is called)
    proxyService.createContentItems(rootCollection, contentItems);     
    
    proxyService.updateContent(contentItem);
    
    proxyService.removeContent(contentItem);
}
 
Example #4
Source File: TimezoneValidator.java    From cosmo with Apache License 2.0 6 votes vote down vote up
public boolean isValid(Calendar value, ConstraintValidatorContext context) {
    if(value==null) {
        return true;
    }
    
    try {
        Calendar calendar = (Calendar) value;
        
        // validate entire icalendar object
        calendar.validate(true);
        
        // make sure we have a VTIMEZONE
        VTimeZone timezone = (VTimeZone) calendar.getComponents()
                .getComponents(Component.VTIMEZONE).get(0);
        return timezone != null;
    } catch(ValidationException ve) {
        return false;
    } catch (RuntimeException e) {
        return false;
    }
}
 
Example #5
Source File: ExternalCalendaringServiceImpl.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Calendar createCalendar(List<VEvent> events, String method, boolean timeIsLocal) {
	
	if(!isIcsEnabled()) {
		log.debug("ExternalCalendaringService is disabled. Enable via calendar.ics.generation.enabled=true in sakai.properties");
		return null;
	}
	
	//setup calendar
	Calendar calendar = setupCalendar(method);
	
	//null check
	if(CollectionUtils.isEmpty(events)) {
		log.error("List of VEvents was null or empty, no calendar will be created.");
		return null;
	}
	
	//add vevents to calendar
	calendar.getComponents().addAll(events);
	
	//add vtimezone
	VTimeZone tz = getTimeZone(timeIsLocal);

	calendar.getComponents().add(tz);
	
	//validate
	try {
		calendar.validate(true);
	} catch (ValidationException e) {
		log.error("createCalendar failed validation", e);
		return null;
	}
	
	if(log.isDebugEnabled()){
		log.debug("Calendar:" + calendar);
	}
	
	return calendar;
	
}
 
Example #6
Source File: ICalendarService.java    From axelor-open-suite with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Export the calendar to the given file.
 *
 * @param calendar the source {@link ICalendar}
 * @param file the target file
 * @throws IOException
 * @throws ParseException
 * @throws ValidationException
 */
public void export(ICalendar calendar, File file)
    throws IOException, ParseException, ValidationException {
  Preconditions.checkNotNull(calendar, "calendar can't be null");
  Preconditions.checkNotNull(file, "input file can't be null");

  final Writer writer = new FileWriter(file);
  try {
    export(calendar, writer);
  } finally {
    writer.close();
  }
}
 
Example #7
Source File: CalendarClientsAdapterTest.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * MKCALENDAR in icalIOS7 provides a timezone without prodid
 * @throws IOException
 * @throws ParserException
 * @throws ValidationException
 */
@Test
public void icalIOS7_missingTimezoneProductIdIsAdded() throws IOException, ParserException, ValidationException{
    Calendar calendar = new CalendarBuilder().build(new ByteArrayInputStream(geticalIOS7Calendar()));
    CalendarClientsAdapter.adaptTimezoneCalendarComponent(calendar);
    calendar.validate(true);//must not throw exceptions
}
 
Example #8
Source File: ExternalCalendaringServiceImpl.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Calendar createCalendar(List<VEvent> events, String method, boolean timeIsLocal) {
	
	if(!isIcsEnabled()) {
		log.debug("ExternalCalendaringService is disabled. Enable via calendar.ics.generation.enabled=true in sakai.properties");
		return null;
	}
	
	//setup calendar
	Calendar calendar = setupCalendar(method);
	
	//null check
	if(CollectionUtils.isEmpty(events)) {
		log.error("List of VEvents was null or empty, no calendar will be created.");
		return null;
	}
	
	//add vevents to calendar
	calendar.getComponents().addAll(events);
	
	//add vtimezone
	VTimeZone tz = getTimeZone(timeIsLocal);

	calendar.getComponents().add(tz);
	
	//validate
	try {
		calendar.validate(true);
	} catch (ValidationException e) {
		log.error("createCalendar failed validation", e);
		return null;
	}
	
	if(log.isDebugEnabled()){
		log.debug("Calendar:" + calendar);
	}
	
	return calendar;
	
}
 
Example #9
Source File: ICalConverter.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
/** Returns a calendar derived from a Work Effort calendar publish point.
 * @param workEffortId ID of a work effort with <code>workEffortTypeId</code> equal to
 * <code>PUBLISH_PROPS</code>.
 * @param context The conversion context
 * @return An iCalendar as a <code>String</code>, or <code>null</code>
 * if <code>workEffortId</code> is invalid.
 * @throws GenericEntityException
 */
public static ResponseProperties getICalendar(String workEffortId, Map<String, Object> context) throws GenericEntityException {
    Delegator delegator = (Delegator) context.get("delegator");
    GenericValue publishProperties = EntityQuery.use(delegator).from("WorkEffort").where("workEffortId", workEffortId).queryOne();
    if (!isCalendarPublished(publishProperties)) {
        Debug.logInfo("WorkEffort calendar is not published: " + workEffortId, module);
        return ICalWorker.createNotFoundResponse(null);
    }
    if (!"WES_PUBLIC".equals(publishProperties.get("scopeEnumId"))) {
        if (context.get("userLogin") == null) {
            return ICalWorker.createNotAuthorizedResponse(null);
        }
        if (!hasPermission(workEffortId, "VIEW", context)) {
            return ICalWorker.createForbiddenResponse(null);
        }
    }
    Calendar calendar = makeCalendar(publishProperties, context);
    ComponentList<CalendarComponent> components = calendar.getComponents();
    List<GenericValue> workEfforts = getRelatedWorkEfforts(publishProperties, context);
    if (workEfforts != null) {
        for (GenericValue workEffort : workEfforts) {
            ResponseProperties responseProps = toCalendarComponent(components, workEffort, context);
            if (responseProps != null) {
                return responseProps;
            }
        }
    }
    if (Debug.verboseOn()) {
        try {
            calendar.validate(true);
            Debug.logVerbose("iCalendar passes validation", module);
        } catch (ValidationException e) {
            if (Debug.verboseOn()) Debug.logVerbose("iCalendar fails validation: " + e, module);
        }
    }
    return ICalWorker.createOkResponse(calendar.toString());
}
 
Example #10
Source File: Calendar_EventServiceAdv.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 获取一个日程事件转换为ICAL后的内容信息
 * @param o2_calendar_event
 * @throws ValidationException
 * @throws IOException
 */
public String getiCalContent( Calendar_Event o2_calendar_event) throws ValidationException, IOException{
	net.fortuna.ical4j.model.Calendar calendar = parseToiCal(o2_calendar_event);
	CalendarOutputter calendarOutputter = new CalendarOutputter(false); 
	ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
	calendarOutputter.output(calendar, baos); 
	return new String(baos.toByteArray(), "utf-8");
}
 
Example #11
Source File: Calendar_EventServiceAdv.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 获取一个日程事件转换为ICAL后的内容信息
 * @param o2_calendar_event
 * @throws ValidationException
 * @throws IOException
 */
public String getiCalContent( Calendar_Event o2_calendar_event) throws ValidationException, IOException{
	net.fortuna.ical4j.model.Calendar calendar = parseToiCal(o2_calendar_event);
	CalendarOutputter calendarOutputter = new CalendarOutputter(false); 
	ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
	calendarOutputter.output(calendar, baos); 
	return new String(baos.toByteArray(), "utf-8");
}
 
Example #12
Source File: ContextServiceExtensionsAdviceTest.java    From cosmo with Apache License 2.0 4 votes vote down vote up
/**
 * If no handler is specified, the event extension data is not created
 * because is not used. the processing continues.
 * @throws IOException 
 * @throws ValidationException 
 */
@Test
public void createEventNotCreatedIfNoHandlers() throws IOException, ValidationException{
    createProxyServiceWithoutExpectedAdviceExecution();
    
    User user = testHelper.makeDummyUser("user1", "password");

    CollectionItem rootCollection = contentDao.createRootItem(user);
    
    //call service
    ContentItem contentItem = testHelper.makeDummyContent(user);
    Set<ContentItem> contentItems = new HashSet<ContentItem>();
    contentItems.add(contentItem);
    //test(fails if getEventData method is called)
    proxyService.createContentItems(rootCollection, contentItems);       

    proxyService.updateContent(contentItem);
    
    proxyService.removeContent(contentItem);

  
}
 
Example #13
Source File: ContextServiceExtensionsAdviceTest.java    From cosmo with Apache License 2.0 4 votes vote down vote up
/**
 * 
 * @throws IOException 
 * @throws ValidationException 
 * @throws URISyntaxException  
 */
@Test
public void testSimpleContentItems() throws IOException, ValidationException, URISyntaxException{
    createProxyServiceWithExpectedAdviceExecution();
    
    User user = testHelper.makeDummyUser("user1", "password");

    CollectionItem rootCollection = contentDao.createRootItem(user);
    
    ContentItem contentItem = createSimpleContentItem(user);
    
    Set<ContentItem> contentItems = new HashSet<ContentItem>();
    contentItems.add(contentItem);
    addSimpleCheckCallExpectedOnHandlers(rootCollection, contentItems);
    
    
    
    
    proxyService.createContentItems(rootCollection, contentItems);
    
    proxyService.updateContent(contentItem);
    
    proxyService.removeContent(contentItem);

}
 
Example #14
Source File: ContextServiceExtensionsAdviceTest.java    From cosmo with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testSimpleAddContent() throws IOException, ValidationException, URISyntaxException{
    createProxyServiceWithExpectedAdviceExecution();
    List<EventAddHandler> lst = new ArrayList<EventAddHandler>();
    EventAddHandler mockAddHandler = Mockito.mock(EventAddHandler.class);
    lst.add(mockAddHandler);
    eventOperationExtensionsAdvice.setAddHandlers(lst);
    User user = testHelper.makeDummyUser("user1", "password");

    CollectionItem rootCollection = contentDao.createRootItem(user);
    
    ContentItem contentItem = createSimpleContentItem(user);
    
         
    
    
    proxyService.createContent(rootCollection, contentItem);
    
    Mockito.verify(mockAddHandler).beforeAdd(Mockito.eq(rootCollection), Mockito.any(Set.class));
}
 
Example #15
Source File: ContextServiceExtensionsAdviceTest.java    From cosmo with Apache License 2.0 4 votes vote down vote up
/**
 * 
 * @throws IOException 
 * @throws ValidationException 
 * @throws URISyntaxException  
 * @throws ParserException  
 */
@Test
public void testContentItemManyAttendees() throws IOException, ValidationException, URISyntaxException, ParserException{
    createProxyServiceWithExpectedAdviceExecution();
    addCheckManyAttendeedCallExpectedOnHandlers();
    
    User user = testHelper.makeDummyUser("user1", "password");

    CollectionItem rootCollection = contentDao.createRootItem(user);
    
    ContentItem contentItem = createContentItemManyAttendees(user);
    
    Set<ContentItem> contentItems = new HashSet<ContentItem>();
    contentItems.add(contentItem);
    
    
    
    proxyService.createContentItems(rootCollection, contentItems);
    
    proxyService.updateContent(contentItem);
    
    proxyService.removeContent(contentItem);
}
 
Example #16
Source File: CalendarUtils.java    From cosmo with Apache License 2.0 3 votes vote down vote up
/**
    * Convert Calendar object to String.
    * 
    * @param calendar
    * @return string representation of calendar
    * @throws ValidationException
    *             - if something is wrong this exception is thrown.
    * @throws IOException
    *             - if something is wrong this exception is thrown.
    */
   public static String outputCalendar(Calendar calendar) throws ValidationException, IOException {
if (calendar == null) {
    return null;
}
CalendarOutputter outputter = new CalendarOutputter();
StringWriter sw = new StringWriter();
outputter.output(calendar, sw);
return sw.toString();
   }
 
Example #17
Source File: ICalendarOutputter.java    From cosmo with Apache License 2.0 3 votes vote down vote up
/**
 * Writes an iCalendar string representing the calendar items contained within the given calendar collection to the
 * given output stream.
 *
 * Since the calendar content stored with each calendar items is parsed and validated when the item is created,
 * these errors should not reoccur when the calendar is being outputted.
 *
 * @param collection the <code>CollectionItem</code> to format
 *
 * @throws IllegalArgumentException if the collection is not stamped as a calendar collection
 * @throws IOException
 */
public static void output(Calendar calendar, OutputStream out) throws IOException {

    CalendarOutputter outputter = new CalendarOutputter();
    outputter.setValidating(false);
    try {
        outputter.output(calendar, out);
    } catch (ValidationException e) {
        throw new IllegalStateException("unable to validate collection calendar", e);
    }
}
 
Example #18
Source File: Calendar_EventServiceAdv.java    From o2oa with GNU Affero General Public License v3.0 3 votes vote down vote up
/**
 * 将一个日程事件写为一个ical文件
 * @param o2_calendar_event
 * @param path
 * @throws ValidationException
 * @throws IOException
 */
public void writeiCal( Calendar_Event o2_calendar_event, String path ) throws ValidationException, IOException{
	net.fortuna.ical4j.model.Calendar calendar = parseToiCal(o2_calendar_event);
	FileOutputStream fout = new FileOutputStream("D://2.ics");
       CalendarOutputter outputter = new CalendarOutputter();
       outputter.output(calendar, fout );
}
 
Example #19
Source File: Calendar_EventServiceAdv.java    From o2oa with GNU Affero General Public License v3.0 3 votes vote down vote up
/**
 * 将一个日程事件写为一个ical文件
 * @param o2_calendar_event
 * @param path
 * @throws ValidationException
 * @throws IOException
 */
public void writeiCal( Calendar_Event o2_calendar_event, String path ) throws ValidationException, IOException{
	net.fortuna.ical4j.model.Calendar calendar = parseToiCal(o2_calendar_event);
	FileOutputStream fout = new FileOutputStream("D://2.ics");
       CalendarOutputter outputter = new CalendarOutputter();
       outputter.output(calendar, fout );
}
 
Example #20
Source File: Calendar_EventServiceAdv.java    From o2oa with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * 将一个日程事件写为一个ical文件
 * @param o2_calendar_event
 * @param out
 * @throws ValidationException
 * @throws IOException
 */
public void wirteiCal( Calendar_Event o2_calendar_event, OutputStream out ) throws ValidationException, IOException{
	net.fortuna.ical4j.model.Calendar calendar = parseToiCal(o2_calendar_event);
       CalendarOutputter outputter = new CalendarOutputter();
       outputter.output(calendar, out );
}
 
Example #21
Source File: Calendar_EventServiceAdv.java    From o2oa with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * 验证一个日历是否符合ICAL要求
 * @param o2_calendar_event
 * @throws ValidationException
 * @throws IOException
 */
public Boolean validateCalendar( Calendar_Event o2_calendar_event ) throws ValidationException, IOException{
	net.fortuna.ical4j.model.Calendar calendar = parseToiCal(o2_calendar_event);
	calendar.validate();
	return true;
}
 
Example #22
Source File: Calendar_EventServiceAdv.java    From o2oa with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * 将一个日程事件写为一个ical文件
 * @param o2_calendar_event
 * @param out
 * @throws ValidationException
 * @throws IOException
 */
public void wirteiCal( Calendar_Event o2_calendar_event, OutputStream out ) throws ValidationException, IOException{
	net.fortuna.ical4j.model.Calendar calendar = parseToiCal(o2_calendar_event);
       CalendarOutputter outputter = new CalendarOutputter();
       outputter.output(calendar, out );
}
 
Example #23
Source File: Calendar_EventServiceAdv.java    From o2oa with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * 验证一个日历是否符合ICAL要求
 * @param o2_calendar_event
 * @throws ValidationException
 * @throws IOException
 */
public Boolean validateCalendar( Calendar_Event o2_calendar_event ) throws ValidationException, IOException{
	net.fortuna.ical4j.model.Calendar calendar = parseToiCal(o2_calendar_event);
	calendar.validate();
	return true;
}