use of fi.otavanopisto.muikku.plugins.material.model.MaterialProducer 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.material.model.MaterialProducer 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.MaterialProducer in project muikku by otavanopisto.
the class HtmlMaterialCloneOperation method clone.
@Override
public HtmlMaterial clone(HtmlMaterial material) {
HtmlMaterial clonedMaterial = htmlMaterialController.createHtmlMaterial(material.getTitle(), material.getHtml(), material.getContentType(), new Long(0), 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.MaterialProducer in project muikku by otavanopisto.
the class MaterialProducerDAO method listByMaterial.
public List<MaterialProducer> listByMaterial(Material material) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<MaterialProducer> criteria = criteriaBuilder.createQuery(MaterialProducer.class);
Root<MaterialProducer> root = criteria.from(MaterialProducer.class);
criteria.select(root);
criteria.where(criteriaBuilder.equal(root.get(MaterialProducer_.material), material));
return entityManager.createQuery(criteria).getResultList();
}
use of fi.otavanopisto.muikku.plugins.material.model.MaterialProducer in project muikku by otavanopisto.
the class MaterialProducerDAO method create.
public MaterialProducer create(Material material, String name) {
MaterialProducer materialProducer = new MaterialProducer();
materialProducer.setName(name);
materialProducer.setMaterial(material);
return persist(materialProducer);
}
Aggregations