Java Code Examples for net.fortuna.ical4j.model.property.RRule#getRecur()

The following examples show how to use net.fortuna.ical4j.model.property.RRule#getRecur() . 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: EventValidator.java    From cosmo with Apache License 2.0 6 votes vote down vote up
private boolean isRRuleValid(RRule rrule, ValidationConfig config) {
    if (rrule == null) {
        return true;
    }

    if (rrule.getRecur() == null || rrule.getRecur().getFrequency() == null) {
        return false;
    }

    String recurFrequency = rrule.getRecur().getFrequency();
    if (!config.getAllowedRecurrenceFrequencies().contains(recurFrequency)) {
        return false;
    }

    return true;
}
 
Example 2
Source File: ICal4JUtils.java    From projectforge-webapp with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 
 * @param rruleString
 * @return null if rruleString is empty, otherwise new RRule object.
 */
public static RRule calculateRecurrenceRule(final String rruleString)
{
  if (StringUtils.isBlank(rruleString) == true) {
    return null;
  }
  try {
    final RRule rule = new RRule(rruleString);
    // set the recurrence end date to the last minute of the day
    final Recur recur = rule.getRecur();
    final net.fortuna.ical4j.model.Date until = recur != null ? recur.getUntil() : null;
    if (until != null) {
      final Date untilEndOfDay = CalendarUtils.getEndOfDay(until, PFUserContext.getTimeZone());
      recur.setUntil(new net.fortuna.ical4j.model.Date(untilEndOfDay));
    }
    return rule;
  } catch (final ParseException ex) {
    log.error("Exception encountered while parsing rrule '" + rruleString + "': " + ex.getMessage(), ex);
    return null;
  }
}
 
Example 3
Source File: TeamEventDO.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Will be renewed if {@link #setRecurrenceRule(String)} is called.
 * @return the recurrenceRuleObject
 */
@Transient
public Recur getRecurrenceObject()
{
  final RRule rrule = getRecurrenceRuleObject();
  return rrule != null ? rrule.getRecur() : null;
}
 
Example 4
Source File: Calendar_EventServiceAdv.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 *  删除重复日程事件中某一事件开始后续所有的日程事件信息(一定是重复日程)
 *  
 * 1、删除当前事件以及该重复事件主体信息已经生成的该ID事件后续时间内所有已经生成的日程事件信息
 * 2、更新日程事件重复信息主体,将截止日期改为指定ID所在的日期的前一天的23:59:59
 * 
 * @param repeatMasterId
 * @param calendar_event
 * @return
 * @throws Exception
 */
public Integer destoryAfterEventId( String repeatMasterId, Calendar_Event calendar_event ) throws Exception {		
	
	if( StringUtils.isEmpty( repeatMasterId )) {
		throw new Exception("calendar repeat master id is empty, calendar can not delete!" );
	}
	
	if( calendar_event == null ) {
		throw new Exception("calendar event is null, calendar can not delete!" );
	}
	
	Integer count = 0;
	Business business = null;
	List<String> eventIds = null;
	List<Calendar_Event> calendarEvents = null;
	Calendar_EventRepeatMaster calendar_EventRepeatMaster = null;
	try ( EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		business = new Business(emc);
		calendar_EventRepeatMaster = emc.find( calendar_event.getRepeatMasterId(), Calendar_EventRepeatMaster.class );
		
		//-----------------------------------------------------------------------------------------------------------------
		//1、删除当前事件以及该重复事件主体信息已经生成的该ID事件后续时间内所有已经生成的日程事件信息
		eventIds = business.calendar_EventFactory().listWithRepeatMaster(repeatMasterId, calendar_event.getStartTime(), null );
		if( ListTools.isNotEmpty( eventIds )) {
			count = eventIds.size();
			calendarEvents = business.calendar_EventFactory().list( eventIds );
		}
		if( ListTools.isNotEmpty( calendarEvents )) {
			emc.beginTransaction( Calendar_Event.class );	
			for( Calendar_Event calendar_Event : calendarEvents ) {
				emc.remove( calendar_Event, CheckRemoveType.all );
			}
		}
		
		//将截止日期改为指定ID所在的日期的前一天的23:59:59
		Date repeatEndTime = dateOperation.getEndTimeInDay( dateOperation.getDayAddDate( calendar_event.getStartTime(), -1 ) );
		RRule rule = new RRule( calendar_EventRepeatMaster.getRecurrenceRule() );
		Recur recur = rule.getRecur();
		recur.setUntil( new net.fortuna.ical4j.model.Date(repeatEndTime) );		
		calendar_EventRepeatMaster.setRecurrenceRule( new RRule(recur).getValue());
		
		emc.beginTransaction( Calendar_EventRepeatMaster.class );
		emc.check( calendar_EventRepeatMaster, CheckPersistType.all );
		emc.commit();
	} catch ( Exception e ) {
		throw e;
	}
	return count;
}
 
Example 5
Source File: Calendar_EventServiceAdv.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 *  删除重复日程事件中某一事件开始后续所有的日程事件信息(一定是重复日程)
 *  
 * 1、删除当前事件以及该重复事件主体信息已经生成的该ID事件后续时间内所有已经生成的日程事件信息
 * 2、更新日程事件重复信息主体,将截止日期改为指定ID所在的日期的前一天的23:59:59
 * 
 * @param repeatMasterId
 * @param calendar_event
 * @return
 * @throws Exception
 */
public Integer destoryAfterEventId( String repeatMasterId, Calendar_Event calendar_event ) throws Exception {		
	
	if( StringUtils.isEmpty( repeatMasterId )) {
		throw new Exception("calendar repeat master id is empty, calendar can not delete!" );
	}
	
	if( calendar_event == null ) {
		throw new Exception("calendar event is null, calendar can not delete!" );
	}
	
	Integer count = 0;
	Business business = null;
	List<String> eventIds = null;
	List<Calendar_Event> calendarEvents = null;
	Calendar_EventRepeatMaster calendar_EventRepeatMaster = null;
	try ( EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		business = new Business(emc);
		calendar_EventRepeatMaster = emc.find( calendar_event.getRepeatMasterId(), Calendar_EventRepeatMaster.class );
		
		//-----------------------------------------------------------------------------------------------------------------
		//1、删除当前事件以及该重复事件主体信息已经生成的该ID事件后续时间内所有已经生成的日程事件信息
		eventIds = business.calendar_EventFactory().listWithRepeatMaster(repeatMasterId, calendar_event.getStartTime(), null );
		if( ListTools.isNotEmpty( eventIds )) {
			count = eventIds.size();
			calendarEvents = business.calendar_EventFactory().list( eventIds );
		}
		if( ListTools.isNotEmpty( calendarEvents )) {
			emc.beginTransaction( Calendar_Event.class );	
			for( Calendar_Event calendar_Event : calendarEvents ) {
				emc.remove( calendar_Event, CheckRemoveType.all );
			}
		}
		
		//将截止日期改为指定ID所在的日期的前一天的23:59:59
		Date repeatEndTime = dateOperation.getEndTimeInDay( dateOperation.getDayAddDate( calendar_event.getStartTime(), -1 ) );
		RRule rule = new RRule( calendar_EventRepeatMaster.getRecurrenceRule() );
		Recur recur = rule.getRecur();
		recur.setUntil( new net.fortuna.ical4j.model.Date(repeatEndTime) );		
		calendar_EventRepeatMaster.setRecurrenceRule( new RRule(recur).getValue());
		
		emc.beginTransaction( Calendar_EventRepeatMaster.class );
		emc.check( calendar_EventRepeatMaster, CheckPersistType.all );
		emc.commit();
	} catch ( Exception e ) {
		throw e;
	}
	return count;
}
 
Example 6
Source File: ICal4JUtils.java    From projectforge-webapp with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @param rruleString
 * @see ICal4JUtils#calculateRecurrenceRule(String)
 * @see RRule#getRecur()
 */
public static Recur calculateRecurrence(final String rruleString)
{
  final RRule rule = calculateRecurrenceRule(rruleString);
  return rule != null ? rule.getRecur() : null;
}