private Attendee convertAttendee(UserDataRequest udr, Event oldEvent) { ParticipationState oldState = ParticipationState.NEEDSACTION; if (oldEvent != null) { for (Attendee oldAtt : oldEvent.getAttendees()) { if (oldAtt.getEmail().equals(udr.getCredentials().getUser().getEmail())) { oldState = oldAtt.getState(); break; } } } Attendee ret = new Attendee(); ret.setEmail(udr.getCredentials().getUser().getEmail()); ret.setParticipationRole(ParticipationRole.REQ); ret.setState(status(oldState, AttendeeStatus.ACCEPT)); return ret; }
public Event convert( UserDataRequest udr, Event oldEvent, MSTask task, Boolean isObmInternalEvent) { Event e = new Event(); e.setInternalEvent(isObmInternalEvent); if (oldEvent != null) { e.setExtId(oldEvent.getExtId()); for (Attendee att : oldEvent.getAttendees()) { if (task.getComplete()) { att.setPercent(100); } else if (att.getPercent() >= 100) { att.setPercent(0); } e.addAttendee(att); } } else { Attendee att = convertAttendee(udr, null); if (task.getComplete()) { att.setPercent(100); } e.addAttendee(att); } e.setType(EventType.VTODO); e.setTitle(task.getSubject()); e.setDescription(task.getDescription()); if (task.getUtcStartDate() != null) { e.setStartDate(task.getUtcStartDate()); e.setTimezoneName("GMT"); } else { Calendar cal = Calendar.getInstance(); cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.HOUR, 0); e.setStartDate(cal.getTime()); } int importance = Objects.firstNonNull(task.getImportance(), TASK_IMPORTANCE_NORMAL); switch (importance) { case 0: e.setPriority(1); break; case 2: e.setPriority(5); break; default: case 1: e.setPriority(3); break; } if (task.getReminderSet()) { long alert = Math.abs(task.getUtcStartDate().getTime() - task.getReminderTime().getTime()); e.setAlert((int) alert); } e.setPrivacy(privacy(oldEvent, task.getSensitivity())); if (task.getUtcDueDate() != null) { long durmili = Math.abs(task.getUtcStartDate().getTime() - task.getUtcDueDate().getTime()); e.setDuration((int) durmili / 1000); } e.setRecurrence(getRecurrence(task)); return e; }