Search in sources :

Example 1 with WorkspaceRootFolder

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();
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceMaterialAssignmentType(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialAssignmentType) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode) WorkspaceRootFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder) Path(javax.ws.rs.Path) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented) GET(javax.ws.rs.GET)

Example 2 with WorkspaceRootFolder

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;
}
Also used : WorkspaceMaterialReply(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialReply) ArrayList(java.util.ArrayList) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) WorkspaceRootFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder)

Example 3 with WorkspaceRootFolder

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);
}
Also used : WorkspaceRootFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder)

Example 4 with WorkspaceRootFolder

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;
}
Also used : ArrayList(java.util.ArrayList) WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode) WorkspaceRootFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder)

Example 5 with WorkspaceRootFolder

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();
    }
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) ServletOutputStream(javax.servlet.ServletOutputStream) Part(javax.servlet.http.Part) HtmlMaterial(fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial) BinaryMaterial(fi.otavanopisto.muikku.plugins.material.model.BinaryMaterial) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) WorkspaceRootFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder)

Aggregations

WorkspaceRootFolder (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder)21 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)14 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)14 Path (javax.ws.rs.Path)12 GET (javax.ws.rs.GET)8 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)7 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)6 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)5 WorkspaceNode (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode)5 RESTPermitUnimplemented (fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)5 ArrayList (java.util.ArrayList)4 POST (javax.ws.rs.POST)3 WorkspaceGradingScale (fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceGradingScale)2 BinaryMaterial (fi.otavanopisto.muikku.plugins.material.model.BinaryMaterial)2 HtmlMaterial (fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial)2 WorkspaceMaterialFileFieldAnswerFile (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialFileFieldAnswerFile)2 GradingScale (fi.otavanopisto.muikku.schooldata.entity.GradingScale)2 GradingScaleItem (fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem)2 IOException (java.io.IOException)2 Date (java.util.Date)2