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();
}
}
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();
}
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();
}
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();
}
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();
}
}
Aggregations