use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder in project muikku by otavanopisto.
the class WorkspaceRESTService method listWorkspaceMaterials.
@GET
@Path("/workspaces/{WORKSPACEENTITYID}/materials/")
@RESTPermitUnimplemented
public Response listWorkspaceMaterials(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @QueryParam("parentId") Long parentId, @QueryParam("assignmentType") String assignmentType) {
if (parentId == null && assignmentType == null) {
return Response.status(Status.NOT_IMPLEMENTED).entity("Listing workspace materials without parentId or assignmentType is currently not implemented").build();
}
WorkspaceMaterialAssignmentType workspaceAssignmentType = null;
if (assignmentType != null) {
workspaceAssignmentType = WorkspaceMaterialAssignmentType.valueOf(assignmentType);
if (workspaceAssignmentType == null) {
return Response.status(Status.BAD_REQUEST).entity("Invalid assignmentType parameter").build();
}
}
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.NOT_FOUND).entity("Could not find a workspace entity").build();
}
List<WorkspaceMaterial> workspaceMaterials = null;
if (parentId != null) {
WorkspaceNode parent = workspaceMaterialController.findWorkspaceNodeById(parentId);
if (parent == null) {
return Response.status(Status.BAD_REQUEST).entity("Given workspace parent material does not exist").build();
}
WorkspaceRootFolder rootFolder = workspaceMaterialController.findWorkspaceRootFolderByWorkspaceNode(parent);
if (rootFolder == null) {
return Response.status(Status.BAD_REQUEST).entity("Could not find a workspace root folder").build();
}
if (!rootFolder.getWorkspaceEntityId().equals(workspaceEntityId)) {
return Response.status(Status.BAD_REQUEST).entity("Invalid parentId").build();
}
if (assignmentType != null) {
workspaceMaterials = workspaceMaterialController.listWorkspaceMaterialsByParentAndAssignmentType(parent, workspaceEntity, workspaceAssignmentType, BooleanPredicate.IGNORE);
workspaceMaterials.removeIf(material -> isHiddenMaterial(material));
} else {
workspaceMaterials = workspaceMaterialController.listWorkspaceMaterialsByParent(parent);
}
} else {
workspaceMaterials = workspaceMaterialController.listWorkspaceMaterialsByAssignmentType(workspaceEntity, workspaceAssignmentType, BooleanPredicate.IGNORE);
workspaceMaterials.removeIf(material -> isHiddenMaterial(material));
}
if (workspaceMaterials.isEmpty()) {
return Response.noContent().build();
}
return Response.ok(createRestModel(workspaceMaterials.toArray(new WorkspaceMaterial[0]))).build();
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder in project muikku by otavanopisto.
the class WorkspaceMaterialReplyController method listVisibleWorkspaceMaterialRepliesByWorkspaceEntity.
public List<WorkspaceMaterialReply> listVisibleWorkspaceMaterialRepliesByWorkspaceEntity(WorkspaceEntity workspaceEntity, UserEntity userEntity) {
List<WorkspaceMaterialReply> workspaceMaterialReplies = new ArrayList<WorkspaceMaterialReply>();
WorkspaceRootFolder rootFolder = workspaceRootFolderDAO.findByWorkspaceEntityId(workspaceEntity.getId());
List<WorkspaceMaterial> workspaceMaterials = new ArrayList<WorkspaceMaterial>();
appendVisibleWorkspaceMaterials(workspaceMaterials, rootFolder);
WorkspaceMaterialReply reply;
for (WorkspaceMaterial workspaceMaterial : workspaceMaterials) {
reply = findWorkspaceMaterialReplyByWorkspaceMaterialAndUserEntity(workspaceMaterial, userEntity);
if (reply != null) {
workspaceMaterialReplies.add(reply);
}
}
return workspaceMaterialReplies;
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder in project muikku by otavanopisto.
the class WorkspaceMaterialController method deleteAllWorkspaceNodes.
public void deleteAllWorkspaceNodes(WorkspaceEntity workspaceEntity) throws WorkspaceMaterialContainsAnswersExeption {
WorkspaceRootFolder rootFolder = findWorkspaceRootFolderByWorkspaceEntity(workspaceEntity);
deleteAllChildNodes(rootFolder);
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder in project muikku by otavanopisto.
the class WorkspaceMaterialController method listWorkspaceMaterialsAsContentNodes.
public List<ContentNode> listWorkspaceMaterialsAsContentNodes(WorkspaceEntity workspaceEntity, boolean includeHidden) throws WorkspaceMaterialException {
List<ContentNode> contentNodes = new ArrayList<>();
WorkspaceRootFolder rootFolder = findWorkspaceRootFolderByWorkspaceEntity(workspaceEntity);
List<WorkspaceNode> rootMaterialNodes = includeHidden ? listWorkspaceNodesByParentAndFolderTypeSortByOrderNumber(rootFolder, WorkspaceFolderType.DEFAULT) : listVisibleWorkspaceNodesByParentAndFolderTypeSortByOrderNumber(rootFolder, WorkspaceFolderType.DEFAULT);
for (WorkspaceNode rootMaterialNode : rootMaterialNodes) {
ContentNode node = createContentNode(rootMaterialNode, 1, true, includeHidden);
contentNodes.add(node);
}
return contentNodes;
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder in project muikku by otavanopisto.
the class MaterialAttachmentUploadServlet method doPost.
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String materialUrl = req.getPathInfo();
if (StringUtils.isBlank(materialUrl)) {
sendResponse(resp, "Missing material path", HttpServletResponse.SC_BAD_REQUEST);
return;
}
if (!sessionController.isLoggedIn()) {
sendResponse(resp, "Unauthorized", HttpServletResponse.SC_UNAUTHORIZED);
return;
}
Part file = req.getPart("upload");
if (file == null) {
sendResponse(resp, "Missing file", HttpServletResponse.SC_BAD_REQUEST);
return;
}
long fileSizeLimit = systemSettingsController.getUploadFileSizeLimit();
if (file.getSize() > fileSizeLimit) {
sendResponse(resp, "File too large", HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE);
return;
}
WorkspaceMaterial parentWorkspaceMaterial = workspaceMaterialController.findWorkspaceMaterialByRootPath(materialUrl);
if (parentWorkspaceMaterial == null) {
sendResponse(resp, "Material not found", HttpServletResponse.SC_NOT_FOUND);
return;
}
WorkspaceRootFolder workspaceRootFolder = workspaceMaterialController.findWorkspaceRootFolderByWorkspaceNode(parentWorkspaceMaterial);
if (workspaceRootFolder == null) {
sendResponse(resp, "Workspace root folder not found", HttpServletResponse.SC_NOT_FOUND);
return;
}
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceRootFolder.getWorkspaceEntityId());
if (workspaceEntity == null) {
sendResponse(resp, "Workspace entity not found", HttpServletResponse.SC_NOT_FOUND);
return;
}
if (!sessionController.hasWorkspacePermission(MuikkuPermissions.MANAGE_WORKSPACE_MATERIALS, workspaceEntity)) {
sendResponse(resp, "Forbidden", HttpServletResponse.SC_FORBIDDEN);
return;
}
HtmlMaterial parentMaterial = htmlMaterialController.findHtmlMaterialById(parentWorkspaceMaterial.getMaterialId());
if (parentMaterial == null) {
sendResponse(resp, "Parent material is not html material", HttpServletResponse.SC_BAD_REQUEST);
return;
}
String license = null;
BinaryMaterial uploadedMaterial = binaryMaterialController.createBinaryMaterial(file.getSubmittedFileName(), file.getContentType(), IOUtils.toByteArray(file.getInputStream()), license);
String uploadedUrl = null;
List<WorkspaceMaterial> parentWorkspaceMaterials = workspaceMaterialController.listWorkspaceMaterialsByMaterial(parentMaterial);
for (WorkspaceMaterial sharedWorkspaceMaterial : parentWorkspaceMaterials) {
WorkspaceMaterial uploadedWorkspaceMaterial = workspaceMaterialController.createWorkspaceMaterial(sharedWorkspaceMaterial, uploadedMaterial);
if (sharedWorkspaceMaterial.getId().equals(parentWorkspaceMaterial.getId())) {
uploadedUrl = uploadedWorkspaceMaterial.getUrlName();
}
}
if (StringUtils.isBlank(uploadedUrl)) {
sendResponse(resp, "Could not resolve uploaded file url", HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
UploadMeta uploadMeta = new UploadMeta(file.getName(), 1, uploadedUrl);
resp.setContentType("application/json");
ServletOutputStream servletOutputStream = resp.getOutputStream();
try {
(new ObjectMapper()).writeValue(servletOutputStream, uploadMeta);
} finally {
servletOutputStream.flush();
}
}
Aggregations