Search in sources :

Example 1 with BinaryMaterial

use of fi.otavanopisto.muikku.plugins.material.model.BinaryMaterial in project muikku by otavanopisto.

the class BinaryMaterialController method updateBinaryMaterialContent.

public BinaryMaterial updateBinaryMaterialContent(BinaryMaterial binaryMaterial, byte[] content) {
    BinaryMaterial material = binaryMaterialDAO.updateContent(binaryMaterial, content);
    materialUpdateEvent.fire(new BinaryMaterialUpdateEvent(material));
    return material;
}
Also used : BinaryMaterialUpdateEvent(fi.otavanopisto.muikku.plugins.material.events.BinaryMaterialUpdateEvent) BinaryMaterial(fi.otavanopisto.muikku.plugins.material.model.BinaryMaterial)

Example 2 with BinaryMaterial

use of fi.otavanopisto.muikku.plugins.material.model.BinaryMaterial in project muikku by otavanopisto.

the class BinaryMaterialController method createBinaryMaterial.

public BinaryMaterial createBinaryMaterial(String title, String contentType, byte[] content, BinaryMaterial originMaterial, String license, MaterialViewRestrict viewRestrict) {
    BinaryMaterial material = binaryMaterialDAO.create(title, contentType, content, originMaterial, license, viewRestrict);
    materialCreateEvent.fire(new BinaryMaterialCreateEvent(material));
    return material;
}
Also used : BinaryMaterialCreateEvent(fi.otavanopisto.muikku.plugins.material.events.BinaryMaterialCreateEvent) BinaryMaterial(fi.otavanopisto.muikku.plugins.material.model.BinaryMaterial)

Example 3 with BinaryMaterial

use of fi.otavanopisto.muikku.plugins.material.model.BinaryMaterial in project muikku by otavanopisto.

the class BinaryMaterialCloneOperation method clone.

@Override
public BinaryMaterial clone(BinaryMaterial material) {
    BinaryMaterial clonedMaterial = binaryMaterialController.createBinaryMaterial(material.getTitle(), material.getContentType(), material.getContent(), material, material.getLicense(), material.getViewRestrict());
    List<MaterialMeta> materialMetas = materialController.listMaterialMetas(material);
    for (MaterialMeta materialMeta : materialMetas) {
        materialController.createMaterialMeta(clonedMaterial, materialMeta.getKey(), materialMeta.getValue());
    }
    List<MaterialProducer> materialProducers = materialController.listMaterialProducers(material);
    for (MaterialProducer materialProducer : materialProducers) {
        materialController.createMaterialProducer(clonedMaterial, materialProducer.getName());
    }
    return clonedMaterial;
}
Also used : MaterialMeta(fi.otavanopisto.muikku.plugins.material.model.MaterialMeta) BinaryMaterial(fi.otavanopisto.muikku.plugins.material.model.BinaryMaterial) MaterialProducer(fi.otavanopisto.muikku.plugins.material.model.MaterialProducer)

Example 4 with BinaryMaterial

use of fi.otavanopisto.muikku.plugins.material.model.BinaryMaterial 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)

Example 5 with BinaryMaterial

use of fi.otavanopisto.muikku.plugins.material.model.BinaryMaterial in project muikku by otavanopisto.

the class BinaryMaterialDAO method create.

public BinaryMaterial create(String title, String contentType, byte[] content, BinaryMaterial originMaterial, String license, MaterialViewRestrict viewRestrict) {
    BinaryMaterial binaryMaterial = new BinaryMaterial();
    binaryMaterial.setContent(content);
    binaryMaterial.setContentType(contentType);
    binaryMaterial.setTitle(title);
    binaryMaterial.setOriginMaterial(originMaterial);
    binaryMaterial.setLicense(license);
    binaryMaterial.setViewRestrict(viewRestrict);
    return persist(binaryMaterial);
}
Also used : BinaryMaterial(fi.otavanopisto.muikku.plugins.material.model.BinaryMaterial)

Aggregations

BinaryMaterial (fi.otavanopisto.muikku.plugins.material.model.BinaryMaterial)12 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)5 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)3 HtmlMaterial (fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial)2 WorkspaceRootFolder (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 URL (java.net.URL)2 Path (javax.ws.rs.Path)2 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)1 BinaryMaterialCreateEvent (fi.otavanopisto.muikku.plugins.material.events.BinaryMaterialCreateEvent)1 BinaryMaterialUpdateEvent (fi.otavanopisto.muikku.plugins.material.events.BinaryMaterialUpdateEvent)1 Material (fi.otavanopisto.muikku.plugins.material.model.Material)1 MaterialMeta (fi.otavanopisto.muikku.plugins.material.model.MaterialMeta)1 MaterialProducer (fi.otavanopisto.muikku.plugins.material.model.MaterialProducer)1 WorkspaceFolder (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder)1 WorkspaceNode (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode)1 RESTPermitUnimplemented (fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)1 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)1