private CalendarEvent newCalendarEvent( String calendarId, String CalType, String type, boolean isPublic) { CalendarEvent categoryEvent = new CalendarEvent(); categoryEvent.setCalendarId(calendarId); categoryEvent.setCalType(CalType); categoryEvent.setDescription(randomWords(20)); if (!isPublic) { EventCategory eventCategory = randomEventCategory(); categoryEvent.setEventCategoryId(eventCategory.getId()); categoryEvent.setEventCategoryName(eventCategory.getName()); } categoryEvent.setEventState(randomState()); categoryEvent.setEventType(type); long time = randomDateTime(rand.nextInt(365), 0); categoryEvent.setFromDateTime(getTime(time)); time = randomDateTime(rand.nextInt(5), time); categoryEvent.setToDateTime(getTime(time)); categoryEvent.setLocation(DEFAULT_LOCATION); categoryEvent.setMessage(randomWords(30)); categoryEvent.setInvitation(new String[] {EMPTY}); categoryEvent.setParticipant(new String[] {currentUser}); categoryEvent.setParticipantStatus(new String[] {currentUser + ":"}); categoryEvent.setPriority(CalendarEvent.PRIORITY[rand.nextInt(CalendarEvent.PRIORITY.length)]); categoryEvent.setSendOption(CalendarSetting.ACTION_NEVER); categoryEvent.setStatus(EMPTY); categoryEvent.setTaskDelegator(EMPTY); categoryEvent.setRepeatType( CalendarEvent.REPEATTYPES[rand.nextInt(CalendarEvent.REPEATTYPES.length)]); categoryEvent.setSummary(calRandomWords(5)); categoryEvent.setPrivate(!isPublic); return categoryEvent; }
private void initPrivateCalendar() throws Exception { log.info("Inject private datas ...."); // save setting try { setting = calService.getCalendarSetting(currentUser); log.info(String.format("Save calendar setting for user %s ....", currentUser)); } catch (Exception e) { setting = newCalendarSetting(); calService.saveCalendarSetting(currentUser, setting); } long t = System.currentTimeMillis(), t1 = t; t = System.currentTimeMillis(); // save EventCategoy List<EventCategory> eventCategories = findEventCategorys(); for (EventCategory evCat : eventCategories) { calService.saveEventCategory(currentUser, evCat, true); eventCategory.add(evCat); eventCategorys.add(evCat.getId()); } log.info( String.format( "Saved %s eventCategories in %sms", eventCategories.size(), (System.currentTimeMillis() - t))); // save calendar List<Calendar> calendars = findCalendars(false); List<CalendarEvent> events; int index = 0, size = calendars.size(), evsCal, evs = 0, tas = 0; for (Calendar calendar : calendars) { t = System.currentTimeMillis(); calService.saveUserCalendar(currentUser, calendar, true); privateCalendar.add(calendar.getId()); // save Event events = findCalendarEvent(calendar.getId(), "0", CalendarEvent.TYPE_EVENT, false); for (CalendarEvent event : events) { calService.saveUserEvent(currentUser, calendar.getId(), event, true); } evsCal = events.size(); evs += evsCal; // save Task events = findCalendarEvent(calendar.getId(), "0", CalendarEvent.TYPE_TASK, false); tas += events.size(); for (CalendarEvent event : events) { calService.saveUserEvent(currentUser, calendar.getId(), event, true); } log.info( String.format( "Saved Calendar %s/%s with %s Events and %s Tasks in %sms", (++index), size, evsCal, events.size(), (System.currentTimeMillis()) - t)); } log.info( String.format( "INITIALIZED EventCategorys=%s / Calendars=%s / Events=%s / Tasks=%s in %sms", eventCategories.size(), calendars.size(), evs, tas, (System.currentTimeMillis() - t1))); saveHistoryInject(); }
public static List<SelectItemOption<String>> getCategory() throws Exception { List<SelectItemOption<String>> options = new ArrayList<SelectItemOption<String>>(); CalendarService calendarService = getCalendarService(); List<EventCategory> eventCategories = calendarService.getEventCategories(getCurrentUser()); for (EventCategory category : eventCategories) { // Check if EventCategory is default event category boolean isDefaultEventCategory = false; for (int i = 0; i < NewUserListener.defaultEventCategoryIds.length; i++) { if (category.getId().equals(NewUserListener.defaultEventCategoryIds[i]) && category.getName().equals(NewUserListener.defaultEventCategoryNames[i])) { isDefaultEventCategory = true; break; } } if (isDefaultEventCategory) { String newName = getResourceBundle("UICalendarView.label." + category.getId(), category.getId()); options.add(new SelectItemOption<String>(newName, category.getId())); } else { options.add(new SelectItemOption<String>(category.getName(), category.getId())); } } return options; }
private EventCategory newEventCategory() { EventCategory eventCategory = new EventCategory(); eventCategory.setDataInit(true); eventCategory.setName(calRandomWords(5)); return eventCategory; }