use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder in project muikku by otavanopisto.
the class WorkspaceRESTService method createWorkspaceMaterialReply.
@POST
// @Path ("/workspaces/{WORKSPACEENTITYID:[0-9]*}/materials/{WORKSPACEMATERIALID:[0-9]*}/replies")
@Path("/workspaces/{WORKSPACEENTITYID}/materials/{WORKSPACEMATERIALID}/replies")
@RESTPermitUnimplemented
public Response createWorkspaceMaterialReply(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("WORKSPACEMATERIALID") Long workspaceMaterialId, WorkspaceMaterialReply payload) {
if (payload == null) {
return Response.status(Status.BAD_REQUEST).entity("Payload is missing").build();
}
if (payload.getState() == null) {
return Response.status(Status.BAD_REQUEST).entity("State is missing").build();
}
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 workspaceMaterialReply = workspaceMaterialReplyController.createWorkspaceMaterialReply(workspaceMaterial, payload.getState(), loggedUser);
return Response.ok(createRestModel(workspaceMaterialReply)).build();
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder in project muikku by otavanopisto.
the class EvaluationRESTService method findWorkspaceMaterialEvaluation.
@GET
@Path("/workspaces/{WORKSPACEENTITYID}/materials/{WORKSPACEMATERIALID}/evaluations/{ID}")
@RESTPermit(handling = Handling.INLINE)
public Response findWorkspaceMaterialEvaluation(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("WORKSPACEMATERIALID") Long workspaceMaterialId, @PathParam("ID") Long workspaceMaterialEvaluationId) {
if (!sessionController.isLoggedIn()) {
return Response.status(Status.UNAUTHORIZED).build();
}
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.NOT_FOUND).build();
}
WorkspaceMaterial workspaceMaterial = workspaceMaterialController.findWorkspaceMaterialById(workspaceMaterialId);
if (workspaceMaterial == null) {
return Response.status(Status.NOT_FOUND).entity("workspaceMaterial not found").build();
}
WorkspaceRootFolder rootFolder = workspaceMaterialController.findWorkspaceRootFolderByWorkspaceNode(workspaceMaterial);
if (rootFolder == null) {
return Response.status(Status.INTERNAL_SERVER_ERROR).build();
}
if (!workspaceEntity.getId().equals(rootFolder.getWorkspaceEntityId())) {
return Response.status(Status.NOT_FOUND).build();
}
fi.otavanopisto.muikku.plugins.evaluation.model.WorkspaceMaterialEvaluation workspaceMaterialEvaluation = evaluationController.findWorkspaceMaterialEvaluation(workspaceMaterialEvaluationId);
if (workspaceMaterialEvaluation == null) {
return Response.status(Status.NOT_FOUND).build();
}
if (!workspaceMaterialEvaluation.getWorkspaceMaterialId().equals(workspaceMaterial.getId())) {
return Response.status(Status.NOT_FOUND).build();
}
if (!sessionController.getLoggedUserEntity().getId().equals(workspaceMaterialEvaluation.getStudentEntityId())) {
if (!sessionController.hasWorkspacePermission(EvaluationResourcePermissionCollection.EVALUATION_FINDWORKSPACEMATERIALEVALUATION, workspaceEntity)) {
return Response.status(Status.FORBIDDEN).build();
}
}
return Response.ok(createRestModel(workspaceMaterialEvaluation)).build();
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder in project muikku by otavanopisto.
the class WorkspaceMaterialController method createWorkspaceRootFolder.
/* Root Folder */
public WorkspaceRootFolder createWorkspaceRootFolder(WorkspaceEntity workspaceEntity) {
WorkspaceRootFolder workspaceRootFolder = workspaceRootFolderDAO.create(workspaceEntity);
workspaceRootFolderCreateEvent.fire(new WorkspaceRootFolderCreateEvent(workspaceRootFolder));
return workspaceRootFolder;
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder in project muikku by otavanopisto.
the class WorkspaceMaterialController method listWorkspaceFolders.
private List<WorkspaceNode> listWorkspaceFolders(WorkspaceEntity workspaceEntity, BooleanPredicate hidden) {
List<WorkspaceNode> result = new ArrayList<>();
WorkspaceRootFolder rootFolder = findWorkspaceRootFolderByWorkspaceEntity(workspaceEntity);
result.add(rootFolder);
appendChildFolders(rootFolder, result, hidden);
return result;
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder in project muikku by otavanopisto.
the class WorkspaceMaterialUploadBackingBean method upload.
public String upload() {
ObjectMapper objectMapper = new ObjectMapper();
if (!sessionController.isLoggedIn()) {
return "/error/internal-error.jsf";
}
// Workspace
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return "/error/internal-error.jsf";
}
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceAndUserIdentifier(workspaceEntity, sessionController.getLoggedUser());
if (workspaceUserEntity == null || workspaceUserEntity.getWorkspaceUserRole() == null || workspaceUserEntity.getWorkspaceUserRole().getArchetype() != WorkspaceRoleArchetype.TEACHER) {
return "/error/internal-error.jsf";
}
WorkspaceNode parent = null;
if (getFolderId() != null) {
WorkspaceFolder workspaceFolder = workspaceMaterialController.findWorkspaceFolderById(getFolderId());
if (workspaceFolder == null) {
return "/error/internal-error.jsf";
}
WorkspaceRootFolder workspaceRootFolder = workspaceMaterialController.findWorkspaceRootFolderByWorkspaceNode(workspaceFolder);
if (workspaceRootFolder == null) {
return "/error/internal-error.jsf";
}
if (!workspaceRootFolder.getWorkspaceEntityId().equals(workspaceEntityId)) {
return "/error/internal-error.jsf";
}
} else {
parent = workspaceMaterialController.findWorkspaceRootFolderByWorkspaceEntity(workspaceEntity);
}
try {
FileMeta[] fileMetas = objectMapper.readValue(getUploadMeta(), FileMeta[].class);
for (FileMeta fileMeta : fileMetas) {
String fileId = fileMeta.getId();
try {
String contentType = fileMeta.getContentType();
String fileName = fileMeta.getName();
byte[] fileData = TempFileUtils.getTempFileData(fileId);
String license = null;
BinaryMaterial binaryMaterial = binaryMaterialController.createBinaryMaterial(fileName, contentType, fileData, license);
workspaceMaterialController.createWorkspaceMaterial(parent, binaryMaterial);
} finally {
TempFileUtils.deleteTempFile(fileId);
}
}
} catch (IOException e) {
logger.log(Level.SEVERE, "File uploading filed", e);
return "/error/internal-error.jsf";
}
return null;
}
Aggregations