Search in sources :

Example 26 with RESTPermitUnimplemented

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();
    }
}
Also used : CalendarServiceException(fi.otavanopisto.muikku.calendar.CalendarServiceException) CalendarEventReminder(fi.otavanopisto.muikku.plugins.calendar.rest.model.CalendarEventReminder) DefaultCalendarEventReminder(fi.otavanopisto.muikku.calendar.DefaultCalendarEventReminder) UserCalendar(fi.otavanopisto.muikku.plugins.calendar.model.UserCalendar) CalendarEventAttendee(fi.otavanopisto.muikku.plugins.calendar.rest.model.CalendarEventAttendee) DefaultCalendarEventAttendee(fi.otavanopisto.muikku.calendar.DefaultCalendarEventAttendee) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)

Example 27 with RESTPermitUnimplemented

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();
    }
}
Also used : DefaultCalendarEventLocation(fi.otavanopisto.muikku.calendar.DefaultCalendarEventLocation) UserCalendar(fi.otavanopisto.muikku.plugins.calendar.model.UserCalendar) CalendarEventAttendee(fi.otavanopisto.muikku.plugins.calendar.rest.model.CalendarEventAttendee) DefaultCalendarEventAttendee(fi.otavanopisto.muikku.calendar.DefaultCalendarEventAttendee) CalendarServiceException(fi.otavanopisto.muikku.calendar.CalendarServiceException) DefaultCalendarEventTemporalField(fi.otavanopisto.muikku.calendar.DefaultCalendarEventTemporalField) CalendarEventReminder(fi.otavanopisto.muikku.plugins.calendar.rest.model.CalendarEventReminder) DefaultCalendarEventReminder(fi.otavanopisto.muikku.calendar.DefaultCalendarEventReminder) DefaultCalendarEvent(fi.otavanopisto.muikku.calendar.DefaultCalendarEvent) Path(javax.ws.rs.Path) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented) PUT(javax.ws.rs.PUT)

Example 28 with RESTPermitUnimplemented

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();
        }
    }
}
Also used : CoOpsUsageException(fi.foyt.coops.CoOpsUsageException) CoOpsNotImplementedException(fi.foyt.coops.CoOpsNotImplementedException) CoOpsInternalErrorException(fi.foyt.coops.CoOpsInternalErrorException) EntityTag(javax.ws.rs.core.EntityTag) CoOpsNotFoundException(fi.foyt.coops.CoOpsNotFoundException) CoOpsForbiddenException(fi.foyt.coops.CoOpsForbiddenException) HtmlMaterial(fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial) CacheControl(javax.ws.rs.core.CacheControl) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) File(fi.foyt.coops.model.File) Path(javax.ws.rs.Path) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented) GET(javax.ws.rs.GET)

Example 29 with RESTPermitUnimplemented

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();
}
Also used : MaterialMeta(fi.otavanopisto.muikku.plugins.material.model.MaterialMeta) MaterialMetaKey(fi.otavanopisto.muikku.plugins.material.model.MaterialMetaKey) Material(fi.otavanopisto.muikku.plugins.material.model.Material) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented) PUT(javax.ws.rs.PUT)

Example 30 with RESTPermitUnimplemented

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();
}
Also used : MaterialMeta(fi.otavanopisto.muikku.plugins.material.model.MaterialMeta) MaterialMetaKey(fi.otavanopisto.muikku.plugins.material.model.MaterialMetaKey) Material(fi.otavanopisto.muikku.plugins.material.model.Material) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented) GET(javax.ws.rs.GET)

Aggregations

RESTPermitUnimplemented (fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)40 Path (javax.ws.rs.Path)40 GET (javax.ws.rs.GET)23 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)20 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)13 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)10 POST (javax.ws.rs.POST)8 Material (fi.otavanopisto.muikku.plugins.material.model.Material)7 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)7 ArrayList (java.util.ArrayList)7 PUT (javax.ws.rs.PUT)6 WorkspaceNode (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode)5 WorkspaceRootFolder (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder)5 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)5 Produces (javax.ws.rs.Produces)5 HtmlMaterial (fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial)4 MaterialMetaKey (fi.otavanopisto.muikku.plugins.material.model.MaterialMetaKey)4 User (fi.otavanopisto.muikku.schooldata.entity.User)4 CacheControl (javax.ws.rs.core.CacheControl)4 EntityTag (javax.ws.rs.core.EntityTag)4