Search in sources :

Example 1 with WorkspaceDetails

use of fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceDetails in project muikku by otavanopisto.

the class WorkspaceRESTService method updateWorkspaceDetails.

@PUT
@Path("/workspaces/{ID}/details")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response updateWorkspaceDetails(@PathParam("ID") Long workspaceEntityId, WorkspaceDetails payload) {
    WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
    if (workspace == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (!sessionController.hasWorkspacePermission(MuikkuPermissions.MANAGE_WORKSPACE_DETAILS, workspaceEntity)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    if ((payload.getExternalViewUrl() != null) && (!StringUtils.equals(workspace.getViewLink(), payload.getExternalViewUrl()))) {
        return Response.status(Status.BAD_REQUEST).entity("externalViewUrl is read-only property").build();
    }
    SchoolDataIdentifier typeIdentifier = null;
    if (payload.getTypeId() != null) {
        typeIdentifier = SchoolDataIdentifier.fromId(payload.getTypeId());
        if (typeIdentifier == null) {
            return Response.status(Status.BAD_REQUEST).entity(String.format("Invlid typeId %s", payload.getTypeId())).build();
        }
    }
    if (!isEqualDateTime(workspace.getBeginDate(), payload.getBeginDate()) || !isEqualDateTime(workspace.getEndDate(), payload.getEndDate()) || !Objects.equals(typeIdentifier, workspace.getWorkspaceTypeId())) {
        workspace.setBeginDate(payload.getBeginDate());
        workspace.setEndDate(payload.getEndDate());
        workspace.setWorkspaceTypeId(typeIdentifier);
        workspaceController.updateWorkspace(workspace);
    }
    String typeId = workspace.getWorkspaceTypeId() != null ? workspace.getWorkspaceTypeId().toId() : null;
    return Response.ok(new WorkspaceDetails(typeId, workspace.getBeginDate(), workspace.getEndDate(), workspace.getViewLink())).build();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceDetails(fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceDetails) Workspace(fi.otavanopisto.muikku.schooldata.entity.Workspace) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) PUT(javax.ws.rs.PUT)

Example 2 with WorkspaceDetails

use of fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceDetails in project muikku by otavanopisto.

the class WorkspaceRESTService method getWorkspaceDetails.

@GET
@Path("/workspaces/{ID}/details")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response getWorkspaceDetails(@PathParam("ID") Long workspaceEntityId) {
    WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (!sessionController.hasWorkspacePermission(MuikkuPermissions.VIEW_WORKSPACE_DETAILS, workspaceEntity)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
    if (workspace == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    String typeId = workspace.getWorkspaceTypeId() != null ? workspace.getWorkspaceTypeId().toId() : null;
    return Response.ok(new WorkspaceDetails(typeId, workspace.getBeginDate(), workspace.getEndDate(), workspace.getViewLink())).build();
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceDetails(fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceDetails) Workspace(fi.otavanopisto.muikku.schooldata.entity.Workspace) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Aggregations

WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)2 WorkspaceDetails (fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceDetails)2 Workspace (fi.otavanopisto.muikku.schooldata.entity.Workspace)2 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)2 Path (javax.ws.rs.Path)2 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)1 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)1 GET (javax.ws.rs.GET)1 PUT (javax.ws.rs.PUT)1