use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial 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.WorkspaceMaterial in project muikku by otavanopisto.
the class WorkspaceMaterialController method ensureWorkspaceFrontPageExists.
public WorkspaceMaterial ensureWorkspaceFrontPageExists(WorkspaceEntity workspace) {
WorkspaceFolder frontPageFolder = findWorkspaceFrontPageFolder(workspace);
if (frontPageFolder == null) {
frontPageFolder = createWorkspaceFrontPageFolder(workspace);
}
WorkspaceMaterial frontPageMaterial = null;
List<WorkspaceMaterial> frontPageMaterials = listWorkspaceMaterialsByParent(frontPageFolder);
if (frontPageMaterials.isEmpty()) {
String title = localeController.getText(sessionController.getLocale(), "plugin.workspace.frontPage.title");
String license = null;
HtmlMaterial htmlMaterial = htmlMaterialController.createHtmlMaterial(title, "", "text/html", 0l, license);
frontPageMaterial = createWorkspaceMaterial(frontPageFolder, htmlMaterial);
} else {
frontPageMaterial = frontPageMaterials.get(0);
}
return frontPageMaterial;
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial in project muikku by otavanopisto.
the class WorkspaceMaterialController method listVisibleEvaluableWorkspaceMaterialsAsContentNodes.
public List<ContentNode> listVisibleEvaluableWorkspaceMaterialsAsContentNodes(WorkspaceEntity workspaceEntity, boolean processHtml) throws WorkspaceMaterialException {
List<ContentNode> result = new ArrayList<>();
List<WorkspaceMaterial> workspaceMaterials = listVisibleWorkspaceMaterialsByAssignmentType(workspaceEntity, WorkspaceMaterialAssignmentType.EVALUATED);
for (WorkspaceMaterial workspaceMaterial : workspaceMaterials) {
result.add(createContentNode(workspaceMaterial, 0, processHtml, false));
}
return result;
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial 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.WorkspaceMaterial in project muikku by otavanopisto.
the class WorkspaceHelpPageBackingBean 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;
}
workspaceEntityId = workspaceEntity.getId();
try {
WorkspaceMaterial helpPage = workspaceMaterialController.ensureWorkspaceHelpPageExists(workspaceEntity);
contentNodes = Arrays.asList(workspaceMaterialController.createContentNode(helpPage));
} catch (WorkspaceMaterialException e) {
logger.log(Level.SEVERE, "Error loading materials", e);
return NavigationRules.INTERNAL_ERROR;
}
workspaceId = workspaceEntity.getId();
workspaceBackingBean.setWorkspaceUrlName(urlName);
workspaceName = workspaceBackingBean.getWorkspaceName();
materialsBaseUrl = String.format("/workspace/%s/materials", workspaceUrlName);
return null;
}
Aggregations