use of fi.otavanopisto.muikku.plugins.calendar.model.UserCalendar in project muikku by otavanopisto.
the class CalendarRESTService method updateEvent.
@PUT
@Path("/calendars/{CALID}/events/{EVTID}")
@RESTPermitUnimplemented
public Response updateEvent(@PathParam("CALID") Long calendarId, @PathParam("EVTID") String eventId, CalendarEvent event) {
if (!sessionController.isLoggedIn()) {
return Response.status(Response.Status.FORBIDDEN).build();
}
if (calendarId == null || StringUtils.isBlank(eventId)) {
return Response.status(Response.Status.NOT_FOUND).build();
}
if (event == null) {
return Response.status(Response.Status.BAD_REQUEST).build();
}
if (StringUtils.isBlank(event.getSummary())) {
return Response.status(Response.Status.BAD_REQUEST).entity("Summary is mandatory").build();
}
UserCalendar userCalendar = calendarController.findUserCalendar(calendarId);
if (userCalendar == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
if (!userCalendar.getUserId().equals(sessionController.getLoggedUserEntity().getId())) {
return Response.status(Response.Status.FORBIDDEN).build();
}
try {
fi.otavanopisto.muikku.calendar.CalendarEvent originalCalendarEvent = calendarController.findCalendarEvent(userCalendar, eventId);
if (originalCalendarEvent == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
List<fi.otavanopisto.muikku.calendar.CalendarEventAttendee> attendees = createEventAttendeeListFromRestModel(event.getAttendees());
List<fi.otavanopisto.muikku.calendar.CalendarEventReminder> reminders = createEventReminderListFromRestModel(event.getReminders());
fi.otavanopisto.muikku.calendar.CalendarEventTemporalField start = new DefaultCalendarEventTemporalField(event.getStart(), event.getStartTimeZone());
fi.otavanopisto.muikku.calendar.CalendarEventTemporalField end = new DefaultCalendarEventTemporalField(event.getEnd(), event.getEndTimeZone());
fi.otavanopisto.muikku.calendar.CalendarEventLocation calendarEventLocation = new DefaultCalendarEventLocation(event.getLocation(), event.getVideoCallLink(), event.getLongitude(), event.getLongitude());
fi.otavanopisto.muikku.calendar.CalendarEvent calendarEvent = new DefaultCalendarEvent(originalCalendarEvent.getId(), originalCalendarEvent.getCalendarId(), originalCalendarEvent.getServiceProvider(), event.getSummary(), event.getDescription(), event.getUrl(), calendarEventLocation, event.getStatus(), attendees, originalCalendarEvent.getOrganizer(), start, end, event.isAllDay(), null, null, event.getExtendedProperties(), reminders, event.getRecurrence());
calendarController.updateCalendarEvent(userCalendar, calendarEvent);
return Response.noContent().build();
} catch (CalendarServiceException e) {
e.printStackTrace();
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
}
}
use of fi.otavanopisto.muikku.plugins.calendar.model.UserCalendar in project muikku by otavanopisto.
the class UserCalendarDAO method create.
public UserCalendar create(String calendarId, String calendarProvider, Long userId, Boolean visible) {
UserCalendar userCalendar = new UserCalendar();
userCalendar.setCalendarId(calendarId);
userCalendar.setCalendarProvider(calendarProvider);
userCalendar.setUserId(userId);
userCalendar.setVisible(visible);
return persist(userCalendar);
}
use of fi.otavanopisto.muikku.plugins.calendar.model.UserCalendar in project muikku by otavanopisto.
the class UserCalendarDAO method findByUserIdAndCalendarProvider.
public UserCalendar findByUserIdAndCalendarProvider(Long userId, String calendarProvider) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<UserCalendar> criteria = criteriaBuilder.createQuery(UserCalendar.class);
Root<UserCalendar> root = criteria.from(UserCalendar.class);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(UserCalendar_.userId), userId), criteriaBuilder.equal(root.get(UserCalendar_.calendarProvider), calendarProvider)));
return getSingleResult(entityManager.createQuery(criteria));
}
use of fi.otavanopisto.muikku.plugins.calendar.model.UserCalendar in project muikku by otavanopisto.
the class UserCalendarDAO method listIdsByUserId.
public List<Long> listIdsByUserId(Long userId) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Long> criteria = criteriaBuilder.createQuery(Long.class);
Root<UserCalendar> root = criteria.from(UserCalendar.class);
criteria.select(root.get(UserCalendar_.id));
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(UserCalendar_.userId), userId)));
return entityManager.createQuery(criteria).getResultList();
}
Aggregations