Search in sources :

Example 31 with RESTPermitUnimplemented

use of fi.otavanopisto.muikku.rest.RESTPermitUnimplemented in project muikku by otavanopisto.

the class BinaryMaterialRESTService method getMaterialContent.

@GET
@Path("/{id}/content")
@RESTPermitUnimplemented
public Response getMaterialContent(@PathParam("id") Long id, @Context Request request) {
    BinaryMaterial material = binaryMaterialController.findBinaryMaterialById(id);
    if (material == null) {
        return Response.status(Status.NOT_FOUND).build();
    } else {
        EntityTag tag = new EntityTag(DigestUtils.md5Hex(String.valueOf(material.getVersion())));
        ResponseBuilder builder = request.evaluatePreconditions(tag);
        if (builder != null) {
            return builder.build();
        }
        CacheControl cacheControl = new CacheControl();
        cacheControl.setMustRevalidate(true);
        return Response.ok(material.getContent()).cacheControl(cacheControl).tag(tag).type(material.getContentType()).build();
    }
}
Also used : EntityTag(javax.ws.rs.core.EntityTag) BinaryMaterial(fi.otavanopisto.muikku.plugins.material.model.BinaryMaterial) CacheControl(javax.ws.rs.core.CacheControl) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Path(javax.ws.rs.Path) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented) GET(javax.ws.rs.GET)

Example 32 with RESTPermitUnimplemented

use of fi.otavanopisto.muikku.rest.RESTPermitUnimplemented in project muikku by otavanopisto.

the class WorkspaceRESTService method getWorkspace.

@GET
@Path("/workspaces/{ID}")
@RESTPermitUnimplemented
public Response getWorkspace(@PathParam("ID") Long workspaceEntityId) {
    WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    Workspace workspace = null;
    schoolDataBridgeSessionController.startSystemSession();
    try {
        workspace = workspaceController.findWorkspace(workspaceEntity);
    } finally {
        schoolDataBridgeSessionController.endSystemSession();
    }
    if (workspace == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    return Response.ok(createRestModel(workspaceEntity, workspace.getName(), workspace.getNameExtension(), workspace.getDescription(), convertWorkspaceCurriculumIds(workspace), workspace.getSubjectIdentifier())).build();
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) Workspace(fi.otavanopisto.muikku.schooldata.entity.Workspace) Path(javax.ws.rs.Path) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented) GET(javax.ws.rs.GET)

Example 33 with RESTPermitUnimplemented

use of fi.otavanopisto.muikku.rest.RESTPermitUnimplemented in project muikku by otavanopisto.

the class WorkspaceRESTService method updateWorkspace.

@PUT
@Path("/workspaces/{WORKSPACEENTITYID}")
@RESTPermitUnimplemented
public Response updateWorkspace(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, fi.otavanopisto.muikku.plugins.workspace.rest.model.Workspace payload) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.UNAUTHORIZED).build();
    }
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.NOT_FOUND).entity(String.format("WorkspaceEntity #%d not found", workspaceEntityId)).build();
    }
    if (!sessionController.hasWorkspacePermission(MuikkuPermissions.PUBLISH_WORKSPACE, workspaceEntity)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    if ((payload.getArchived() != null) && payload.getArchived()) {
        return Response.status(Status.NOT_IMPLEMENTED).entity("Archiving workspaces is currently unimplemented").build();
    }
    Workspace workspace = null;
    try {
        workspace = workspaceController.findWorkspace(workspaceEntity);
        if (workspace == null) {
            return Response.status(Status.NOT_FOUND).entity(String.format("Could not find a workspace for WorkspaceEntity #%d", workspaceEntityId)).build();
        }
    } catch (Exception e) {
        return Response.status(Status.INTERNAL_SERVER_ERROR).entity(String.format("Failed to retrieve workspace from school data source (%s)", e.getMessage())).build();
    }
    if ((payload.getDescription() != null) || (payload.getName() != null)) {
        try {
            if ((!StringUtils.equals(payload.getName(), workspace.getName())) || (!StringUtils.equals(payload.getDescription(), workspace.getDescription())) || (!StringUtils.equals(payload.getNameExtension(), workspace.getNameExtension()))) {
                workspace.setName(payload.getName());
                workspace.setNameExtension(payload.getNameExtension());
                workspace.setDescription(payload.getDescription());
                workspace = workspaceController.updateWorkspace(workspace);
            }
        } catch (Exception e) {
            return Response.status(Status.INTERNAL_SERVER_ERROR).entity(String.format("Failed to update workspace data into school data source (%s)", e.getMessage())).build();
        }
    }
    if (payload.getNumVisits() != null) {
        if (workspaceVisitController.getNumVisits(workspaceEntity) != payload.getNumVisits().longValue()) {
            return Response.status(Status.NOT_IMPLEMENTED).entity("Updating number of visit via this endpoint is currently unimplemented").build();
        }
    }
    if (payload.getLastVisit() != null) {
        if (workspaceVisitController.getLastVisit(workspaceEntity).equals(payload.getLastVisit())) {
            return Response.status(Status.NOT_IMPLEMENTED).entity("Updating last visit via this endpoint is currently unimplemented").build();
        }
    }
    if (payload.getPublished() != null && !workspaceEntity.getPublished().equals(payload.getPublished())) {
        workspaceEntity = workspaceEntityController.updatePublished(workspaceEntity, payload.getPublished());
    }
    workspaceEntity = workspaceEntityController.updateAccess(workspaceEntity, payload.getAccess());
    workspaceEntity = workspaceEntityController.updateDefaultMaterialLicense(workspaceEntity, payload.getMaterialDefaultLicense());
    // Reindex the workspace so that Elasticsearch can react to publish and visibility
    workspaceIndexer.indexWorkspace(workspaceEntity);
    return Response.ok(createRestModel(workspaceEntity, workspace.getName(), workspace.getNameExtension(), workspace.getDescription(), convertWorkspaceCurriculumIds(workspace), workspace.getSubjectIdentifier())).build();
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceFieldIOException(fi.otavanopisto.muikku.plugins.workspace.fieldio.WorkspaceFieldIOException) IOException(java.io.IOException) Workspace(fi.otavanopisto.muikku.schooldata.entity.Workspace) Path(javax.ws.rs.Path) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented) PUT(javax.ws.rs.PUT)

Example 34 with RESTPermitUnimplemented

use of fi.otavanopisto.muikku.rest.RESTPermitUnimplemented in project muikku by otavanopisto.

the class WorkspaceRESTService method addJournalEntry.

@POST
@Path("/workspaces/{WORKSPACEID}/journal")
@RESTPermitUnimplemented
public Response addJournalEntry(@PathParam("WORKSPACEID") Long workspaceEntityId, WorkspaceJournalEntryRESTModel restModel) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.UNAUTHORIZED).build();
    }
    WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    workspaceJournalController.createJournalEntry(workspaceController.findWorkspaceEntityById(workspaceEntityId), sessionController.getLoggedUserEntity(), restModel.getContent(), restModel.getTitle());
    return Response.noContent().build();
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)

Example 35 with RESTPermitUnimplemented

use of fi.otavanopisto.muikku.rest.RESTPermitUnimplemented in project muikku by otavanopisto.

the class WorkspaceRESTService method listWorkspaceMaterialReplies.

@GET
@Path("/workspaces/{WORKSPACEENTITYID}/materials/{WORKSPACEMATERIALID}/replies")
@RESTPermitUnimplemented
public Response listWorkspaceMaterialReplies(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("WORKSPACEMATERIALID") Long workspaceMaterialId) {
    UserEntity loggedUser = sessionController.getLoggedUserEntity();
    if (loggedUser == null) {
        return Response.status(Status.UNAUTHORIZED).entity("Unauthorized").build();
    }
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.NOT_FOUND).entity("Could not find workspace entity").build();
    }
    WorkspaceMaterial workspaceMaterial = workspaceMaterialController.findWorkspaceMaterialById(workspaceMaterialId);
    if (workspaceMaterial == null) {
        return Response.status(Status.NOT_FOUND).entity("Could not find workspace material").build();
    }
    WorkspaceRootFolder workspaceRootFolder = workspaceMaterialController.findWorkspaceRootFolderByWorkspaceNode(workspaceMaterial);
    if (workspaceRootFolder == null) {
        return Response.status(Status.INTERNAL_SERVER_ERROR).entity("Could not find workspace root folder").build();
    }
    if (!workspaceRootFolder.getWorkspaceEntityId().equals(workspaceEntity.getId())) {
        return Response.status(Status.BAD_REQUEST).entity("Invalid workspace material id or workspace entity id").build();
    }
    fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialReply materialReply = workspaceMaterialReplyController.findWorkspaceMaterialReplyByWorkspaceMaterialAndUserEntity(workspaceMaterial, loggedUser);
    if (materialReply != null) {
        return Response.ok(createRestModel(new fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialReply[] { materialReply })).build();
    } else {
        return Response.ok(createRestModel(new fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialReply[] {})).build();
    }
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) WorkspaceRootFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder) Path(javax.ws.rs.Path) 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