Search in sources :

Example 1 with MaterialProducer

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()), ",", "&#44;"));
                    }
                }
                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);
    }
}
Also used : Transformer(javax.xml.transform.Transformer) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) HTMLConfiguration(org.cyberneko.html.HTMLConfiguration) Material(fi.otavanopisto.muikku.plugins.material.model.Material) HtmlMaterial(fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) MaterialProducer(fi.otavanopisto.muikku.plugins.material.model.MaterialProducer) WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) WorkspaceFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder) SAXNotSupportedException(org.xml.sax.SAXNotSupportedException) DOMParser(org.apache.xerces.parsers.DOMParser) HtmlMaterial(fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial)

Example 2 with MaterialProducer

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;
}
Also used : MaterialMeta(fi.otavanopisto.muikku.plugins.material.model.MaterialMeta) BinaryMaterial(fi.otavanopisto.muikku.plugins.material.model.BinaryMaterial) MaterialProducer(fi.otavanopisto.muikku.plugins.material.model.MaterialProducer)

Example 3 with MaterialProducer

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;
}
Also used : MaterialMeta(fi.otavanopisto.muikku.plugins.material.model.MaterialMeta) HtmlMaterial(fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial) MaterialProducer(fi.otavanopisto.muikku.plugins.material.model.MaterialProducer)

Example 4 with MaterialProducer

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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) MaterialProducer(fi.otavanopisto.muikku.plugins.material.model.MaterialProducer)

Example 5 with MaterialProducer

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);
}
Also used : MaterialProducer(fi.otavanopisto.muikku.plugins.material.model.MaterialProducer)

Aggregations

MaterialProducer (fi.otavanopisto.muikku.plugins.material.model.MaterialProducer)5 HtmlMaterial (fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial)2 MaterialMeta (fi.otavanopisto.muikku.plugins.material.model.MaterialMeta)2 BinaryMaterial (fi.otavanopisto.muikku.plugins.material.model.BinaryMaterial)1 Material (fi.otavanopisto.muikku.plugins.material.model.Material)1 WorkspaceFolder (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder)1 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)1 WorkspaceNode (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode)1 EntityManager (javax.persistence.EntityManager)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Transformer (javax.xml.transform.Transformer)1 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)1 DOMParser (org.apache.xerces.parsers.DOMParser)1 HTMLConfiguration (org.cyberneko.html.HTMLConfiguration)1 SAXNotRecognizedException (org.xml.sax.SAXNotRecognizedException)1 SAXNotSupportedException (org.xml.sax.SAXNotSupportedException)1