ews-java-api学习:新建Recurring Meeting

    /**
     * Meeting:创建重复会议
     */
    private void createRecurringMeeting(String userName, String password, String domain, String required, String optional, String subject, String location, String startsTime, String endsTime, String recurrenceType, String recurrenceEndsDate, String body, boolean isAllDay) {
        EWS ews = new EWS();
        ExchangeService service = ews.connectEWS(userName, password, domain);
        String[] requiredList, optionalList;
        try {
            Appointment appointment = new Appointment(service);
            // 中国标准时间
            TimeZoneDefinition tz = getTimeZoneDefinition(service, TIME_ZONE_CTT);
            // 会议被邀请人
            if (!required.equals("") && !required.equals(null)) {
                requiredList = required.split("\\|");
                for (String r : requiredList) {
                    appointment.getRequiredAttendees().add(r);
                }
            } 
            if (!optional.equals("") && !optional.equals(null)) {
                optionalList = optional.split("\\|");
                for (String o : optionalList) {
                    appointment.getOptionalAttendees().add(o);
                }
            }
            if ((required.equals("") || required.equals(null)) && (optional.equals("") || optional.equals(null))) {
                System.out.println("输入无效!");
                return;
            }
            appointment.setSubject(subject); // 约会标题
            appointment.setLocation(location); // 约会地点
            appointment.setBody(MessageBody.getMessageBodyFromText(body)); // 约会正文
            // 约会开始时间和结束时间
            HashMap times = getStartsAndEndsTime(startsTime, endsTime);
            appointment.setStart((Date) times.get("startsTime"));
            appointment.setStartTimeZone(tz);
            appointment.setEnd((Date) times.get("endsTime")); 
            appointment.setEndTimeZone(tz);
            // 约会循环类型
            Date dateRecurrenceStarts = appointment.getStart();
            Date dateRecurrenceEnds = getRecurrenceEndsDate(recurrenceEndsDate);
            Recurrence recurrences = null;
            switch(recurrenceType.toLowerCase()) {
            case "daily":
                recurrences = new Recurrence.DailyPattern(dateRecurrenceStarts, 1); // 默认interval为1天
                break;
            case "weekly":
                /**
                 * @param 重复会议开始日期
                 * @param 重复间隔为一周一次
                 * @param 重复会议发生在每周星期一
                 */
                recurrences = new Recurrence.WeeklyPattern(dateRecurrenceStarts, 1, DayOfTheWeek.Monday); // 默认每周一
                break;
            case "monthly":
                /**
                 * @param 重复会议开始日期
                 * @param 重复间隔为一月一次
                 * @param 重复会议发生在每月一号
                 */
                recurrences = new Recurrence.MonthlyPattern(dateRecurrenceStarts, 1, 1); // 默认每月一号
                break;
            case "yearly":
                /**
                 * @param 重复会议开始日期
                 * @param 重复间隔为一年一次
                 * @param 重复会议发生在每年六月一号
                 */
                recurrences = new Recurrence.YearlyPattern(dateRecurrenceStarts, Month.June, 1); // 默认每月一号
                break;
            default:
                System.out.println("输入无效!");
                break;
            }
            appointment.setRecurrence(recurrences);
            appointment.getRecurrence().setStartDate(dateRecurrenceStarts);
            appointment.getRecurrence().setEndDate(dateRecurrenceEnds);
            appointment.setIsAllDayEvent(isAllDay); // 是否全天事件
            appointment.save(WellKnownFolderName.Calendar);
        } catch (Exception e) {
            System.out.println("Error: Fail to create appointment!");
            e.printStackTrace();
        }
    }

你可能感兴趣的:(ews-java-api学习:新建Recurring Meeting)