use of fi.otavanopisto.muikku.schooldata.entity.Workspace 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.schooldata.entity.Workspace in project muikku by otavanopisto.
the class WorkspaceRESTService method getWorkspaceFileContent.
@GET
@Path("/workspaces/{WORKSPACEID}/workspacefile/{FILEIDENTIFIER}")
@RESTPermit(handling = Handling.INLINE)
public Response getWorkspaceFileContent(@PathParam("WORKSPACEID") Long workspaceId, @PathParam("FILEIDENTIFIER") String fileIdentifier, @Context Request request) {
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceId);
if (workspaceEntity == null)
return Response.status(Status.BAD_REQUEST).build();
WorkspaceEntityFile imageFile = workspaceEntityFileController.findWorkspaceEntityFile(workspaceEntity, fileIdentifier);
if (imageFile == null)
return Response.status(Status.NOT_FOUND).build();
StreamingOutput output = s -> fileController.outputFileToStream("workspace", imageFile.getDiskName(), s);
String contentType = imageFile.getContentType();
String tagIdentifier = String.format("%d-%s-%d", imageFile.getWorkspaceEntity(), imageFile.getDiskName(), imageFile.getLastModified().getTime());
EntityTag tag = new EntityTag(DigestUtils.md5Hex(String.valueOf(tagIdentifier)));
ResponseBuilder builder = request.evaluatePreconditions(tag);
if (builder != null) {
return builder.build();
}
CacheControl cacheControl = new CacheControl();
cacheControl.setMustRevalidate(true);
return Response.ok().cacheControl(cacheControl).tag(tag).type(contentType).entity(output).build();
}
use of fi.otavanopisto.muikku.schooldata.entity.Workspace 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.schooldata.entity.Workspace 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();
}
Aggregations