use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.
the class WorkspaceMaterialController method findWorkspaceMaterialByRootPath.
public WorkspaceMaterial findWorkspaceMaterialByRootPath(String path) {
if (path.contains("?")) {
path = StringUtils.substringBefore(path, "?");
}
String[] pathElements = StringUtils.split(path, "/");
if (pathElements.length >= 3 && StringUtils.equals("workspace", pathElements[0]) && StringUtils.equals("materials", pathElements[2])) {
String workspaceUrlName = pathElements[1];
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceByUrlName(workspaceUrlName);
if (workspaceEntity != null) {
WorkspaceNode workspaceNode = findWorkspaceRootFolderByWorkspaceEntity(workspaceEntity);
for (int i = 3; i < pathElements.length; i++) {
workspaceNode = findWorkspaceNodeByParentAndUrlName(workspaceNode, pathElements[i]);
if (workspaceNode == null) {
return null;
}
}
return workspaceNode instanceof WorkspaceMaterial ? (WorkspaceMaterial) workspaceNode : null;
}
}
return null;
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.
the class WorkspaceMaterialUploadBackingBean method init.
@RequestAction
public String init() {
String urlName = getWorkspaceUrlName();
if (StringUtils.isBlank(urlName)) {
return "/error/not-found.jsf";
}
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityByUrlName(urlName);
if (workspaceEntity == null) {
return "/error/not-found.jsf";
}
workspaceEntityId = workspaceEntity.getId();
workspaceBackingBean.setWorkspaceUrlName(urlName);
workspaceName = workspaceBackingBean.getWorkspaceName();
return null;
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity 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;
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.
the class WorkspaceMaterialsBackingBean method init.
@RequestAction
public String init() {
String urlName = getWorkspaceUrlName();
if (StringUtils.isBlank(urlName)) {
return NavigationRules.NOT_FOUND;
}
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityByUrlName(urlName);
if (workspaceEntity == null) {
return NavigationRules.NOT_FOUND;
}
if (!workspaceEntity.getPublished()) {
if (!sessionController.hasWorkspacePermission(MuikkuPermissions.ACCESS_UNPUBLISHED_WORKSPACE, workspaceEntity)) {
return NavigationRules.NOT_FOUND;
}
}
if (workspaceEntity.getAccess() != WorkspaceAccess.ANYONE) {
if (!sessionController.hasWorkspacePermission(MuikkuPermissions.ACCESS_WORKSPACE_MATERIALS, workspaceEntity)) {
if (!sessionController.isLoggedIn()) {
return navigationController.requireLogin();
} else {
return NavigationRules.ACCESS_DENIED;
}
}
}
rootFolder = workspaceMaterialController.findWorkspaceRootFolderByWorkspaceEntity(workspaceEntity);
workspaceEntityId = workspaceEntity.getId();
workspaceBackingBean.setWorkspaceUrlName(urlName);
workspaceName = workspaceBackingBean.getWorkspaceName();
workspaceNameExtension = workspaceBackingBean.getWorkspaceNameExtension();
try {
contentNodes = workspaceMaterialController.listWorkspaceMaterialsAsContentNodes(workspaceEntity, false);
} catch (WorkspaceMaterialException e) {
logger.log(Level.SEVERE, "Error loading materials", e);
return NavigationRules.INTERNAL_ERROR;
}
materialsBaseUrl = String.format("/workspace/%s/materials", workspaceUrlName);
maySignUp = resolveMaySignUp();
canSignUp = sessionController.hasWorkspacePermission(MuikkuPermissions.WORKSPACE_SIGNUP, workspaceEntity);
workspaceVisitController.visit(workspaceEntity);
return null;
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.
the class WorkspaceMaterialsReadingBackingBean method init.
@RequestAction
public String init() {
String urlName = getWorkspaceUrlName();
if (StringUtils.isBlank(urlName)) {
return NavigationRules.NOT_FOUND;
}
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityByUrlName(urlName);
if (workspaceEntity == null) {
return NavigationRules.NOT_FOUND;
}
if (!workspaceEntity.getPublished()) {
if (!sessionController.hasWorkspacePermission(MuikkuPermissions.ACCESS_UNPUBLISHED_WORKSPACE, workspaceEntity)) {
return NavigationRules.NOT_FOUND;
}
}
if (workspaceEntity.getAccess() != WorkspaceAccess.ANYONE) {
if (!sessionController.hasWorkspacePermission(MuikkuPermissions.ACCESS_WORKSPACE_MATERIALS, workspaceEntity)) {
if (!sessionController.isLoggedIn()) {
return navigationController.requireLogin();
} else {
return NavigationRules.ACCESS_DENIED;
}
}
}
rootFolder = workspaceMaterialController.findWorkspaceRootFolderByWorkspaceEntity(workspaceEntity);
workspaceEntityId = workspaceEntity.getId();
workspaceBackingBean.setWorkspaceUrlName(urlName);
workspaceName = workspaceBackingBean.getWorkspaceName();
materialsBaseUrl = String.format("/workspace/%s/materials", workspaceUrlName);
try {
contentNodes = workspaceMaterialController.listWorkspaceMaterialsAsContentNodes(workspaceEntity, false);
} catch (WorkspaceMaterialException e) {
logger.log(Level.SEVERE, "Error loading materials", e);
return NavigationRules.INTERNAL_ERROR;
}
return null;
}
Aggregations