use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial in project muikku by otavanopisto.
the class WorkspaceMaterialController method createContentNode.
private ContentNode createContentNode(WorkspaceNode rootMaterialNode, int level, boolean processHtml, boolean includeHidden) throws WorkspaceMaterialException {
boolean viewRestricted = false;
try {
switch(rootMaterialNode.getType()) {
case FOLDER:
WorkspaceFolder workspaceFolder = (WorkspaceFolder) rootMaterialNode;
viewRestricted = !sessionController.isLoggedIn() && workspaceFolder.getViewRestrict() == MaterialViewRestrict.LOGGED_IN;
ContentNode folderContentNode = new ContentNode(workspaceFolder.getTitle(), "folder", rootMaterialNode.getId(), null, level, null, null, rootMaterialNode.getParent().getId(), rootMaterialNode.getHidden(), null, 0l, 0l, workspaceFolder.getPath(), null, null, workspaceFolder.getViewRestrict(), viewRestricted);
List<WorkspaceNode> children = includeHidden ? workspaceNodeDAO.listByParentSortByOrderNumber(workspaceFolder) : workspaceNodeDAO.listByParentAndHiddenSortByOrderNumber(workspaceFolder, Boolean.FALSE);
List<FlattenedWorkspaceNode> flattenedChildren;
if (level >= FLATTENING_LEVEL) {
flattenedChildren = flattenWorkspaceNodes(children, level, includeHidden);
} else {
flattenedChildren = new ArrayList<>();
for (WorkspaceNode node : children) {
flattenedChildren.add(new FlattenedWorkspaceNode(false, null, node, level, node.getParent().getId(), node.getHidden()));
}
}
for (FlattenedWorkspaceNode child : flattenedChildren) {
ContentNode contentNode;
if (child.isEmptyFolder) {
contentNode = new ContentNode(child.emptyFolderTitle, "folder", rootMaterialNode.getId(), null, child.level, null, null, child.parentId, child.hidden, null, 0l, 0l, child.node.getPath(), null, null, MaterialViewRestrict.NONE, false);
} else {
contentNode = createContentNode(child.node, child.level, processHtml, includeHidden);
}
folderContentNode.addChild(contentNode);
}
return folderContentNode;
case MATERIAL:
DOMParser parser = null;
Transformer transformer = null;
if (processHtml) {
parser = new DOMParser(new HTMLConfiguration());
parser.setProperty("http://cyberneko.org/html/properties/names/elems", "lower");
transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.INDENT, "no");
}
WorkspaceMaterial workspaceMaterial = (WorkspaceMaterial) rootMaterialNode;
Material material = materialController.findMaterialById(workspaceMaterial.getMaterialId());
Long currentRevision = material instanceof HtmlMaterial ? htmlMaterialController.lastHtmlMaterialRevision((HtmlMaterial) material) : 0l;
Long publishedRevision = material instanceof HtmlMaterial ? ((HtmlMaterial) material).getRevisionNumber() : 0l;
List<String> producerNames = null;
String html;
List<MaterialProducer> producers = materialController.listMaterialProducers(material);
if ((producers != null) && !producers.isEmpty()) {
producerNames = new ArrayList<>();
for (MaterialProducer producer : producers) {
producerNames.add(StringUtils.replace(StringEscapeUtils.escapeHtml4(producer.getName()), ",", ","));
}
}
viewRestricted = !sessionController.isLoggedIn() && material.getViewRestrict() == MaterialViewRestrict.LOGGED_IN;
if (!viewRestricted) {
html = processHtml ? getMaterialHtml(material, parser, transformer) : null;
} else {
html = String.format("<p class=\"content-view-restricted-message\">%s</p>", localeController.getText(sessionController.getLocale(), "plugin.workspace.materialViewRestricted"));
}
return new ContentNode(workspaceMaterial.getTitle(), material.getType(), rootMaterialNode.getId(), material.getId(), level, workspaceMaterial.getAssignmentType(), workspaceMaterial.getCorrectAnswers(), workspaceMaterial.getParent().getId(), workspaceMaterial.getHidden(), html, currentRevision, publishedRevision, workspaceMaterial.getPath(), material.getLicense(), StringUtils.join(producerNames, ','), material.getViewRestrict(), viewRestricted);
default:
return null;
}
} catch (SAXNotRecognizedException | SAXNotSupportedException | TransformerConfigurationException e) {
throw new WorkspaceMaterialException(e);
}
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial in project muikku by otavanopisto.
the class WorkspaceMaterialDAO method listByMaterialId.
public List<WorkspaceMaterial> listByMaterialId(long materialId) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<WorkspaceMaterial> criteria = criteriaBuilder.createQuery(WorkspaceMaterial.class);
Root<WorkspaceMaterial> root = criteria.from(WorkspaceMaterial.class);
criteria.select(root);
criteria.where(criteriaBuilder.equal(root.get(WorkspaceMaterial_.materialId), materialId));
return entityManager.createQuery(criteria).getResultList();
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial in project muikku by otavanopisto.
the class WorkspaceMaterialDAO method create.
public WorkspaceMaterial create(WorkspaceNode parent, long materialId, String title, String urlName, Integer orderNumber, Boolean hidden, WorkspaceMaterialAssignmentType assignmentType, WorkspaceMaterialCorrectAnswersDisplay correctAnswers) {
WorkspaceMaterial workspaceMaterial = new WorkspaceMaterial();
workspaceMaterial.setParent(parent);
workspaceMaterial.setMaterialId(materialId);
workspaceMaterial.setUrlName(urlName);
workspaceMaterial.setOrderNumber(orderNumber);
workspaceMaterial.setHidden(hidden);
workspaceMaterial.setAssignmentType(assignmentType);
workspaceMaterial.setCorrectAnswers(correctAnswers);
workspaceMaterial.setTitle(title);
return persist(workspaceMaterial);
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial in project muikku by otavanopisto.
the class WorkspaceMaterialDAO method listByParent.
public List<WorkspaceMaterial> listByParent(WorkspaceNode parent) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<WorkspaceMaterial> criteria = criteriaBuilder.createQuery(WorkspaceMaterial.class);
Root<WorkspaceMaterial> root = criteria.from(WorkspaceMaterial.class);
criteria.select(root);
criteria.where(criteriaBuilder.equal(root.get(WorkspaceMaterial_.parent), parent));
return entityManager.createQuery(criteria).getResultList();
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial in project muikku by otavanopisto.
the class WorkspaceMaterialDAO method findByFolderAndUrlName.
public WorkspaceMaterial findByFolderAndUrlName(WorkspaceNode parent, String urlName) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<WorkspaceMaterial> criteria = criteriaBuilder.createQuery(WorkspaceMaterial.class);
Root<WorkspaceMaterial> root = criteria.from(WorkspaceMaterial.class);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(WorkspaceMaterial_.parent), parent), criteriaBuilder.equal(root.get(WorkspaceMaterial_.urlName), urlName)));
return getSingleResult(entityManager.createQuery(criteria));
}
Aggregations