use of fi.otavanopisto.muikku.rest.RESTPermitUnimplemented in project muikku by otavanopisto.
the class CalendarRESTService method createEvent.
@POST
@Path("/calendars/{CALID:[0-9]*}/events/")
@RESTPermitUnimplemented
public Response createEvent(@PathParam("CALID") Long calendarId, CalendarEvent event) {
if (!sessionController.isLoggedIn()) {
return Response.status(Response.Status.FORBIDDEN).build();
}
if (event == null) {
return Response.status(Response.Status.BAD_REQUEST).entity("Event payload is missing").build();
}
if (calendarId == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
if (StringUtils.isBlank(event.getSummary())) {
return Response.status(Response.Status.BAD_REQUEST).entity("Event summarys is required").build();
}
if (event.getStatus() == null) {
return Response.status(Response.Status.BAD_REQUEST).entity("Event status is required").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 {
List<fi.otavanopisto.muikku.calendar.CalendarEventAttendee> attendees = createEventAttendeeListFromRestModel(event.getAttendees());
List<fi.otavanopisto.muikku.calendar.CalendarEventReminder> reminders = createEventReminderListFromRestModel(event.getReminders());
fi.otavanopisto.muikku.calendar.CalendarEvent calendarEvent = calendarController.createCalendarEvent(userCalendar, event.getSummary(), event.getDescription(), event.getStatus(), event.getStart(), event.getStartTimeZone(), event.getEnd(), event.getEndTimeZone(), attendees, reminders, event.getRecurrence(), event.isAllDay(), event.getExtendedProperties());
return Response.ok(createEventRestModel(userCalendar, calendarEvent)).build();
} catch (CalendarServiceException e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
}
}
use of fi.otavanopisto.muikku.rest.RESTPermitUnimplemented 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.rest.RESTPermitUnimplemented in project muikku by otavanopisto.
the class HtmlMaterialRESTService method findMaterial.
@GET
@Path("/{id}")
@RESTPermitUnimplemented
public Response findMaterial(@PathParam("id") Long id, @QueryParam("revision") Long revision, @Context Request request) {
HtmlMaterial htmlMaterial = htmlMaterialController.findHtmlMaterialById(id);
if (htmlMaterial == null) {
return Response.status(Status.NOT_FOUND).build();
} else {
EntityTag tag = new EntityTag(DigestUtils.md5Hex(String.valueOf(revision == null ? htmlMaterial.getRevisionNumber() : revision)));
ResponseBuilder builder = request.evaluatePreconditions(tag);
if (builder != null) {
return builder.build();
}
CacheControl cacheControl = new CacheControl();
cacheControl.setMustRevalidate(true);
if (revision == null) {
return Response.ok(createRestModel(htmlMaterial)).build();
} else {
File fileRevision;
try {
fileRevision = coOpsApi.fileGet(id.toString(), revision);
} catch (CoOpsNotImplementedException | CoOpsNotFoundException | CoOpsUsageException | CoOpsInternalErrorException | CoOpsForbiddenException e) {
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
}
if (fileRevision == null) {
return Response.status(Status.NOT_FOUND).build();
}
return Response.ok(createRestModel(htmlMaterial, fileRevision)).build();
}
}
}
use of fi.otavanopisto.muikku.rest.RESTPermitUnimplemented in project muikku by otavanopisto.
the class MaterialMetaRESTService method updateMaterialMeta.
@PUT
@Path("/materials/{id}/meta/{KEY}")
@Produces(MediaType.APPLICATION_JSON)
@RESTPermitUnimplemented
public Response updateMaterialMeta(@PathParam("id") Long id, @PathParam("KEY") String key, fi.otavanopisto.muikku.plugins.material.rest.MaterialMeta payload) {
if (!sessionController.isLoggedIn()) {
return Response.status(Status.UNAUTHORIZED).build();
}
if (!sessionController.hasEnvironmentPermission(MuikkuPermissions.MANAGE_MATERIAL_META)) {
return Response.status(Status.FORBIDDEN).build();
}
if (payload.getKey() != null && !StringUtils.equals(payload.getKey(), key)) {
return Response.status(Status.BAD_REQUEST).entity("Can not update material meta key").build();
}
Material material = materialController.findMaterialById(id);
if (material == null) {
return Response.status(Status.NOT_FOUND).entity("Material not found").build();
}
MaterialMetaKey materialMetaKey = materialController.findMaterialMetaKey(key);
if (materialMetaKey == null) {
return Response.status(Status.BAD_REQUEST).entity("Invalid key").build();
}
MaterialMeta materialMeta = materialController.findMaterialMeta(material, materialMetaKey);
if (materialMeta == null) {
return Response.status(Status.BAD_REQUEST).entity("MaterialMeta not found").build();
}
return Response.ok(createRestModel(materialController.updateMaterialMeta(materialMeta, payload.getValue()))).build();
}
use of fi.otavanopisto.muikku.rest.RESTPermitUnimplemented in project muikku by otavanopisto.
the class MaterialMetaRESTService method findMaterialMeta.
@GET
@Path("/materials/{id}/meta/{KEY}")
@Produces(MediaType.APPLICATION_JSON)
@RESTPermitUnimplemented
public Response findMaterialMeta(@PathParam("id") Long id, @PathParam("KEY") String key) {
Material material = materialController.findMaterialById(id);
if (material == null) {
return Response.status(Status.NOT_FOUND).entity("Material not found").build();
}
MaterialMetaKey materialMetaKey = materialController.findMaterialMetaKey(key);
if (materialMetaKey == null) {
return Response.status(Status.BAD_REQUEST).entity("Invalid key").build();
}
MaterialMeta materialMeta = materialController.findMaterialMeta(material, materialMetaKey);
if (materialMeta == null) {
return Response.status(Status.NOT_FOUND).entity("Material meta not found").build();
}
return Response.ok(createRestModel(materialMeta)).build();
}
Aggregations