Search in sources :

Example 6 with WorkspaceNode

use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode in project muikku by otavanopisto.

the class WorkspaceMaterialController method cloneWorkspaceNode.

private WorkspaceNode cloneWorkspaceNode(WorkspaceNode workspaceNode, WorkspaceNode parent, boolean cloneMaterials, boolean overrideCloneMaterials) {
    WorkspaceNode newNode;
    boolean isHtmlMaterial = false;
    Integer index = workspaceNodeDAO.getMaximumOrderNumber(parent);
    index = index == null ? 0 : ++index;
    if (workspaceNode instanceof WorkspaceMaterial) {
        WorkspaceMaterial workspaceMaterial = (WorkspaceMaterial) workspaceNode;
        Material material = getMaterialForWorkspaceMaterial(workspaceMaterial);
        isHtmlMaterial = material instanceof HtmlMaterial;
        Material clonedMaterial = cloneMaterials && !overrideCloneMaterials ? materialController.cloneMaterial(material) : material;
        // Implementation of feature #1232 (front and help pages should always be copies)
        if (isHtmlMaterial && !cloneMaterials) {
            WorkspaceNode parentNode = workspaceMaterial.getParent();
            if (parentNode instanceof WorkspaceFolder) {
                WorkspaceFolder parentFolder = (WorkspaceFolder) parentNode;
                if (parentFolder.getFolderType() == WorkspaceFolderType.FRONT_PAGE || parentFolder.getFolderType() == WorkspaceFolderType.HELP_PAGE) {
                    clonedMaterial = materialController.cloneMaterial(material);
                }
            }
        }
        newNode = createWorkspaceMaterial(parent, clonedMaterial, workspaceMaterial.getTitle(), generateUniqueUrlName(parent, workspaceMaterial.getUrlName()), index, workspaceMaterial.getHidden(), workspaceMaterial.getAssignmentType(), workspaceMaterial.getCorrectAnswers());
    } else if (workspaceNode instanceof WorkspaceFolder) {
        newNode = createWorkspaceFolder(parent, ((WorkspaceFolder) workspaceNode).getTitle(), generateUniqueUrlName(parent, workspaceNode.getUrlName()), index, workspaceNode.getHidden(), ((WorkspaceFolder) workspaceNode).getFolderType(), ((WorkspaceFolder) workspaceNode).getViewRestrict());
    } else {
        throw new IllegalArgumentException("Uncloneable workspace node " + workspaceNode.getClass());
    }
    List<WorkspaceNode> childNodes = workspaceNodeDAO.listByParentSortByOrderNumber(workspaceNode);
    for (WorkspaceNode childNode : childNodes) {
        cloneWorkspaceNode(childNode, newNode, cloneMaterials, isHtmlMaterial);
    }
    return newNode;
}
Also used : Material(fi.otavanopisto.muikku.plugins.material.model.Material) HtmlMaterial(fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) HtmlMaterial(fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial) WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) WorkspaceFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder)

Example 7 with WorkspaceNode

use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode in project muikku by otavanopisto.

the class WorkspaceMaterialController method flattenWorkspaceNodes.

public List<FlattenedWorkspaceNode> flattenWorkspaceNodes(List<WorkspaceNode> workspaceNodes, int level, boolean includeHidden) {
    List<FlattenedWorkspaceNode> result = new ArrayList<>();
    for (WorkspaceNode workspaceNode : workspaceNodes) {
        if (workspaceNode.getType() == WorkspaceNodeType.FOLDER) {
            WorkspaceFolder workspaceFolder = (WorkspaceFolder) workspaceNode;
            List<WorkspaceNode> children = includeHidden ? workspaceNodeDAO.listByParentSortByOrderNumber(workspaceFolder) : workspaceNodeDAO.listByParentAndHiddenSortByOrderNumber(workspaceFolder, Boolean.FALSE);
            result.add(new FlattenedWorkspaceNode(true, workspaceFolder.getTitle(), workspaceFolder, level, workspaceFolder.getParent().getId(), workspaceFolder.getHidden()));
            result.addAll(flattenWorkspaceNodes(children, level + 1, includeHidden));
        } else {
            result.add(new FlattenedWorkspaceNode(false, null, workspaceNode, level, workspaceNode.getParent().getId(), workspaceNode.getHidden()));
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode) WorkspaceFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder)

Example 8 with WorkspaceNode

use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode in project muikku by otavanopisto.

the class WorkspaceMaterialController method generateUniqueUrlName.

public synchronized String generateUniqueUrlName(WorkspaceNode parent, WorkspaceNode targetNode, String title) {
    String urlName = generateUrlName(title);
    String fileName = StringUtils.substringBeforeLast(urlName, ".");
    String extension = StringUtils.substringAfterLast(urlName, ".");
    int extensionLength = StringUtils.length(extension);
    boolean isFileName = StringUtils.isAlphanumeric(extension) && extensionLength < StringUtils.length(urlName) - 1;
    // use urlName as base and uniqueName as final result
    String uniqueName = urlName;
    if (parent != null) {
        // if parent node is given, ensure that the generated url name is unique amongst its child nodes
        int i = 1;
        while (true) {
            // find child node with uniqueName
            WorkspaceNode workspaceNode = workspaceNodeDAO.findByParentAndUrlName(parent, uniqueName);
            if (workspaceNode != null) {
                if (targetNode != null && workspaceNode.getId().equals(targetNode.getId())) {
                    // uniqueName is in use but by the target node itself, so it's okay
                    break;
                }
                // uniqueName in use, try again with the next candidate (name, name-2, name-3, etc.)
                uniqueName = isFileName ? String.format("%s-%d.%s", fileName, ++i, extension) : String.format("%s-%d", urlName, ++i);
            } else {
                // Current uniqueName is available
                break;
            }
        }
    }
    return uniqueName;
}
Also used : WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode)

Example 9 with WorkspaceNode

use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode in project muikku by otavanopisto.

the class WorkspaceMaterialController method listWorkspaceMaterialsAsContentNodes.

public List<ContentNode> listWorkspaceMaterialsAsContentNodes(WorkspaceEntity workspaceEntity, boolean includeHidden) throws WorkspaceMaterialException {
    List<ContentNode> contentNodes = new ArrayList<>();
    WorkspaceRootFolder rootFolder = findWorkspaceRootFolderByWorkspaceEntity(workspaceEntity);
    List<WorkspaceNode> rootMaterialNodes = includeHidden ? listWorkspaceNodesByParentAndFolderTypeSortByOrderNumber(rootFolder, WorkspaceFolderType.DEFAULT) : listVisibleWorkspaceNodesByParentAndFolderTypeSortByOrderNumber(rootFolder, WorkspaceFolderType.DEFAULT);
    for (WorkspaceNode rootMaterialNode : rootMaterialNodes) {
        ContentNode node = createContentNode(rootMaterialNode, 1, true, includeHidden);
        contentNodes.add(node);
    }
    return contentNodes;
}
Also used : ArrayList(java.util.ArrayList) WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode) WorkspaceRootFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder)

Example 10 with WorkspaceNode

use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode in project muikku by otavanopisto.

the class WorkspaceMaterialController method findWorkspaceNodeByWorkspaceEntityAndPath.

public WorkspaceNode findWorkspaceNodeByWorkspaceEntityAndPath(WorkspaceEntity workspaceEntity, String path) {
    String[] pathElements = path.split("/");
    WorkspaceNode parent = findWorkspaceRootFolderByWorkspaceEntity(workspaceEntity);
    for (int i = 0, l = pathElements.length; i < l - 1; i++) {
        String pathElement = pathElements[i];
        parent = findWorkspaceNodeByParentAndUrlName(parent, pathElement);
    }
    return findWorkspaceNodeByParentAndUrlName(parent, pathElements[pathElements.length - 1]);
}
Also used : WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode)

Aggregations

WorkspaceNode (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode)41 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)14 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)11 WorkspaceFolder (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder)11 HtmlMaterial (fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial)9 IOException (java.io.IOException)9 Path (javax.ws.rs.Path)9 ArrayList (java.util.ArrayList)8 EntityManager (javax.persistence.EntityManager)8 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)8 DeusNexInternalException (fi.otavanopisto.muikku.plugins.dnm.parser.DeusNexInternalException)6 Material (fi.otavanopisto.muikku.plugins.material.model.Material)6 RESTPermitUnimplemented (fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)6 TransformerException (javax.xml.transform.TransformerException)6 XPathExpressionException (javax.xml.xpath.XPathExpressionException)6 SAXException (org.xml.sax.SAXException)6 WorkspaceRootFolder (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder)5 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)5 Resource (fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Resource)4 WorkspaceMaterialAssignmentType (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialAssignmentType)4