Search in sources :

Example 1 with Resource

use of fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Resource in project muikku by otavanopisto.

the class DeusNexMachinaController method importResource.

private void importResource(WorkspaceNode importRoot, WorkspaceNode parent, Resource resource, DeusNexDocument deusNexDocument, List<WorkspaceNode> createdNodes) throws DeusNexException {
    WorkspaceNode node = findNode(parent, resource);
    if (resource.getType() == Type.FOLDER) {
        Folder folderResource = (Folder) resource;
        WorkspaceFolder folder = null;
        if (node instanceof WorkspaceFolder) {
            folder = (WorkspaceFolder) node;
        }
        if (folder == null) {
            folder = createFolder(parent, folderResource);
            try {
                setResourceWorkspaceNodeId(resource.getNo(), folder.getId());
            } catch (IOException e) {
                throw new DeusNexInternalException("Failed to store resourceNo lookup file", e);
            }
            createdNodes.add(folder);
        }
        for (Resource childResource : folderResource.getResources()) {
            importResource(importRoot, folder, childResource, deusNexDocument, createdNodes);
        }
    } else {
        if (node == null) {
            logger.fine("importing " + resource.getPath());
            Material material = createMaterial(importRoot, resource, deusNexDocument);
            if (material != null) {
                WorkspaceMaterialAssignmentType assignmentType = null;
                if (resource instanceof Query) {
                    switch(((Query) resource).getQueryType()) {
                        case "1":
                            assignmentType = WorkspaceMaterialAssignmentType.EXERCISE;
                            break;
                        case "2":
                            assignmentType = WorkspaceMaterialAssignmentType.EVALUATED;
                            break;
                    }
                } else if (material instanceof HtmlMaterial) {
                    assignmentType = determineEmbeddedAssignmentType((HtmlMaterial) material);
                }
                WorkspaceMaterial workspaceMaterial = workspaceMaterialController.createWorkspaceMaterial(parent, material, resource.getName(), assignmentType, WorkspaceMaterialCorrectAnswersDisplay.ALWAYS);
                try {
                    setResourceWorkspaceNodeId(resource.getNo(), workspaceMaterial.getId());
                } catch (IOException e) {
                    throw new DeusNexInternalException("Failed to store resourceNo lookup file", e);
                }
                if (resource instanceof ResourceContainer) {
                    List<Resource> childResources = ((ResourceContainer) resource).getResources();
                    if (childResources != null) {
                        for (Resource childResource : childResources) {
                            importResource(importRoot, workspaceMaterial, childResource, deusNexDocument, createdNodes);
                        }
                    }
                }
                if (resource.getHidden()) {
                    workspaceMaterialController.hideWorkspaceNode(workspaceMaterial);
                }
                createdNodes.add(workspaceMaterial);
            }
        } else {
            logger.info(node.getPath() + " already exists, skipping");
        }
    }
}
Also used : Query(fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Query) DeusNexInternalException(fi.otavanopisto.muikku.plugins.dnm.parser.DeusNexInternalException) Resource(fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Resource) Material(fi.otavanopisto.muikku.plugins.material.model.Material) HtmlMaterial(fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial) BinaryMaterial(fi.otavanopisto.muikku.plugins.material.model.BinaryMaterial) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) IOException(java.io.IOException) WorkspaceMaterialAssignmentType(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialAssignmentType) WorkspaceFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder) Folder(fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Folder) WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) WorkspaceFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder) HtmlMaterial(fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial) ResourceContainer(fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.ResourceContainer)

Example 2 with Resource

use of fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Resource in project muikku by otavanopisto.

the class DeusNexMachinaController method importDeusNexDocument.

public void importDeusNexDocument(WorkspaceNode parentNode, InputStream inputStream) throws DeusNexException {
    DeusNexDocument desNexDocument = parseDeusNexDocument(inputStream);
    List<WorkspaceNode> createdNodes = new ArrayList<>();
    for (Resource resource : desNexDocument.getRootFolder().getResources()) {
        importResource(parentNode, parentNode, resource, desNexDocument, createdNodes);
    }
    try {
        postProcessResources(createdNodes);
    } catch (Exception e) {
        throw new DeusNexInternalException("PostProcesssing failed. ", e);
    }
    materialUnEmbedder.unembedWorkspaceMaterials(parentNode);
}
Also used : DeusNexDocument(fi.otavanopisto.muikku.plugins.dnm.parser.structure.DeusNexDocument) DeusNexInternalException(fi.otavanopisto.muikku.plugins.dnm.parser.DeusNexInternalException) ArrayList(java.util.ArrayList) Resource(fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Resource) WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode) XPathExpressionException(javax.xml.xpath.XPathExpressionException) SAXException(org.xml.sax.SAXException) TransformerException(javax.xml.transform.TransformerException) DeusNexException(fi.otavanopisto.muikku.plugins.dnm.parser.DeusNexException) IOException(java.io.IOException) DeusNexInternalException(fi.otavanopisto.muikku.plugins.dnm.parser.DeusNexInternalException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 3 with Resource

use of fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Resource in project muikku by otavanopisto.

the class DeusNexMachinaController method importHelpPageDocument.

public void importHelpPageDocument(WorkspaceEntity workspaceEntity, InputStream inputStream) throws DeusNexException {
    DeusNexDocument deusNexDocument = parseDeusNexDocument(inputStream);
    List<Resource> resources = deusNexDocument.getRootFolder().getResources();
    if (!resources.isEmpty()) {
        List<WorkspaceNode> createdNodes = new ArrayList<>();
        WorkspaceFolder workspaceHelpPageFolder = workspaceMaterialController.createWorkspaceHelpPageFolder(workspaceEntity);
        for (Resource resource : deusNexDocument.getRootFolder().getResources()) {
            importResource(workspaceHelpPageFolder, workspaceHelpPageFolder, resource, deusNexDocument, createdNodes);
        }
        try {
            postProcessResources(createdNodes);
        } catch (Exception e) {
            throw new DeusNexInternalException("PostProcesssing failed. ", e);
        }
    }
}
Also used : DeusNexDocument(fi.otavanopisto.muikku.plugins.dnm.parser.structure.DeusNexDocument) DeusNexInternalException(fi.otavanopisto.muikku.plugins.dnm.parser.DeusNexInternalException) Resource(fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Resource) ArrayList(java.util.ArrayList) WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode) XPathExpressionException(javax.xml.xpath.XPathExpressionException) SAXException(org.xml.sax.SAXException) TransformerException(javax.xml.transform.TransformerException) DeusNexException(fi.otavanopisto.muikku.plugins.dnm.parser.DeusNexException) IOException(java.io.IOException) DeusNexInternalException(fi.otavanopisto.muikku.plugins.dnm.parser.DeusNexInternalException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) WorkspaceFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder)

Example 4 with Resource

use of fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Resource in project muikku by otavanopisto.

the class DeusNexMachinaController method importFrontPageDocument.

public void importFrontPageDocument(WorkspaceEntity workspaceEntity, InputStream inputStream) throws DeusNexException {
    DeusNexDocument deusNexDocument = parseDeusNexDocument(inputStream);
    List<Resource> resources = deusNexDocument.getRootFolder().getResources();
    if (!resources.isEmpty()) {
        List<WorkspaceNode> createdNodes = new ArrayList<>();
        WorkspaceFolder workspaceFrontPageFolder = workspaceMaterialController.createWorkspaceFrontPageFolder(workspaceEntity);
        for (Resource resource : deusNexDocument.getRootFolder().getResources()) {
            importResource(workspaceFrontPageFolder, workspaceFrontPageFolder, resource, deusNexDocument, createdNodes);
        }
        try {
            postProcessResources(createdNodes);
        } catch (Exception e) {
            throw new DeusNexInternalException("PostProcesssing failed. ", e);
        }
    }
}
Also used : DeusNexDocument(fi.otavanopisto.muikku.plugins.dnm.parser.structure.DeusNexDocument) DeusNexInternalException(fi.otavanopisto.muikku.plugins.dnm.parser.DeusNexInternalException) Resource(fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Resource) ArrayList(java.util.ArrayList) WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode) XPathExpressionException(javax.xml.xpath.XPathExpressionException) SAXException(org.xml.sax.SAXException) TransformerException(javax.xml.transform.TransformerException) DeusNexException(fi.otavanopisto.muikku.plugins.dnm.parser.DeusNexException) IOException(java.io.IOException) DeusNexInternalException(fi.otavanopisto.muikku.plugins.dnm.parser.DeusNexInternalException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) WorkspaceFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder)

Example 5 with Resource

use of fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Resource in project muikku by otavanopisto.

the class DeusNexStructureParser method parseFCKDocument.

private Document parseFCKDocument(Element resourceElement) throws DeusNexSyntaxException, XPathExpressionException, DeusNexInternalException {
    Element documentElement = (Element) DeusNexXmlUtils.findNodeByXPath(resourceElement, "document");
    if (documentElement == null) {
        logger.severe("Missing data/document node");
        return null;
    }
    List<Resource> embeddedElements = new ArrayList<>();
    List<Element> embeddedResourceElements = DeusNexXmlUtils.getElementsByXPath(resourceElement, "embedded/res");
    for (Element embeddedResourceElement : embeddedResourceElements) {
        Resource resource = parseResource(embeddedResourceElement);
        if (resource != null) {
            embeddedElements.add(resource);
        }
    }
    Document document = new Document();
    parseBasicResourceProperties(resourceElement, document);
    document.setDocument(documentElement);
    document.setResources(embeddedElements);
    return document;
}
Also used : Element(org.w3c.dom.Element) Resource(fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Resource) ArrayList(java.util.ArrayList) Document(fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Document)

Aggregations

Resource (fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Resource)10 ArrayList (java.util.ArrayList)8 Element (org.w3c.dom.Element)5 DeusNexInternalException (fi.otavanopisto.muikku.plugins.dnm.parser.DeusNexInternalException)4 WorkspaceNode (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode)4 IOException (java.io.IOException)4 DeusNexException (fi.otavanopisto.muikku.plugins.dnm.parser.DeusNexException)3 DeusNexDocument (fi.otavanopisto.muikku.plugins.dnm.parser.structure.DeusNexDocument)3 Query (fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Query)3 WorkspaceFolder (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 TransformerException (javax.xml.transform.TransformerException)3 XPathExpressionException (javax.xml.xpath.XPathExpressionException)3 SAXException (org.xml.sax.SAXException)3 Document (fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Document)2 Folder (fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Folder)2 ResourceContainer (fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.ResourceContainer)2 BinaryMaterial (fi.otavanopisto.muikku.plugins.material.model.BinaryMaterial)1 HtmlMaterial (fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial)1 Material (fi.otavanopisto.muikku.plugins.material.model.Material)1