use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode 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.plugins.workspace.model.WorkspaceNode in project muikku by otavanopisto.
the class WorkspaceMaterialController method moveBelow.
/**
* Updates the order numbers of workspace nodes so that <code>workspaceNode</code> appears below <code>referenceNode</code>.
*
* @param workspaceNode
* The workspace node to be moved
* @param referenceNode
* The workspace node below which <code>workspaceNode</code> is moved
*
* @return The updated workspace node
*/
public WorkspaceNode moveBelow(WorkspaceNode workspaceNode, WorkspaceNode referenceNode) {
// Order number of the reference node
Integer referenceOrderNumber = referenceNode.getOrderNumber() == null ? 0 : referenceNode.getOrderNumber();
// Workspace nodes with order number > reference order number
List<WorkspaceNode> subsequentNodes = workspaceNodeDAO.listByOrderNumberGreater(referenceNode);
// Sort workspace nodes according to order number
sortWorkspaceNodes(subsequentNodes);
// node order number = referenceOrderNumber + 1, subsequent nodes = ++referenceOrderNumber
workspaceNode = workspaceNodeDAO.updateOrderNumber(workspaceNode, ++referenceOrderNumber);
for (WorkspaceNode subsequentNode : subsequentNodes) {
workspaceNodeDAO.updateOrderNumber(subsequentNode, ++referenceOrderNumber);
}
return workspaceNode;
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode in project muikku by otavanopisto.
the class WorkspaceMaterialController method listWorkspaceFolders.
private List<WorkspaceNode> listWorkspaceFolders(WorkspaceEntity workspaceEntity, BooleanPredicate hidden) {
List<WorkspaceNode> result = new ArrayList<>();
WorkspaceRootFolder rootFolder = findWorkspaceRootFolderByWorkspaceEntity(workspaceEntity);
result.add(rootFolder);
appendChildFolders(rootFolder, result, hidden);
return result;
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode in project muikku by otavanopisto.
the class WorkspaceMaterialController method deleteWorkspaceMaterial.
public void deleteWorkspaceMaterial(WorkspaceMaterial workspaceMaterial, boolean removeAnswers) throws WorkspaceMaterialContainsAnswersExeption {
try {
workspaceMaterialDeleteEvent.fire(new WorkspaceMaterialDeleteEvent(workspaceMaterial, removeAnswers));
List<WorkspaceNode> childNodes = workspaceNodeDAO.listByParentSortByOrderNumber(workspaceMaterial);
for (WorkspaceNode childNode : childNodes) {
if (childNode instanceof WorkspaceMaterial) {
deleteWorkspaceMaterial((WorkspaceMaterial) childNode, removeAnswers);
} else if (childNode instanceof WorkspaceFolder) {
deleteWorkspaceFolder((WorkspaceFolder) childNode);
}
}
} catch (Exception e) {
Throwable cause = e;
while (cause != null) {
cause = cause.getCause();
if (cause instanceof WorkspaceMaterialContainsAnswersExeption) {
throw (WorkspaceMaterialContainsAnswersExeption) cause;
}
}
throw e;
}
workspaceMaterialDAO.delete(workspaceMaterial);
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode 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;
}
Aggregations