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;
}
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;
}
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;
}
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();
}
}
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);
}
Aggregations