Search in sources :

Example 26 with WorkspaceNode

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

the class WorkspaceMaterialController method findWorkspaceMaterialByRootPath.

public WorkspaceMaterial findWorkspaceMaterialByRootPath(String path) {
    if (path.contains("?")) {
        path = StringUtils.substringBefore(path, "?");
    }
    String[] pathElements = StringUtils.split(path, "/");
    if (pathElements.length >= 3 && StringUtils.equals("workspace", pathElements[0]) && StringUtils.equals("materials", pathElements[2])) {
        String workspaceUrlName = pathElements[1];
        WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceByUrlName(workspaceUrlName);
        if (workspaceEntity != null) {
            WorkspaceNode workspaceNode = findWorkspaceRootFolderByWorkspaceEntity(workspaceEntity);
            for (int i = 3; i < pathElements.length; i++) {
                workspaceNode = findWorkspaceNodeByParentAndUrlName(workspaceNode, pathElements[i]);
                if (workspaceNode == null) {
                    return null;
                }
            }
            return workspaceNode instanceof WorkspaceMaterial ? (WorkspaceMaterial) workspaceNode : null;
        }
    }
    return null;
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)

Example 27 with WorkspaceNode

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

the class WorkspaceMaterialController method moveBelow.

/**
 * Updates the order numbers of workspace nodes so that <code>workspaceNode</code> appears below <code>referenceNode</code>.
 *
 * @param workspaceNode
 *          The workspace node to be moved
 * @param referenceNode
 *          The workspace node below which <code>workspaceNode</code> is moved
 *
 * @return The updated workspace node
 */
public WorkspaceNode moveBelow(WorkspaceNode workspaceNode, WorkspaceNode referenceNode) {
    // Order number of the reference node
    Integer referenceOrderNumber = referenceNode.getOrderNumber() == null ? 0 : referenceNode.getOrderNumber();
    // Workspace nodes with order number > reference order number
    List<WorkspaceNode> subsequentNodes = workspaceNodeDAO.listByOrderNumberGreater(referenceNode);
    // Sort workspace nodes according to order number
    sortWorkspaceNodes(subsequentNodes);
    // node order number = referenceOrderNumber + 1, subsequent nodes = ++referenceOrderNumber
    workspaceNode = workspaceNodeDAO.updateOrderNumber(workspaceNode, ++referenceOrderNumber);
    for (WorkspaceNode subsequentNode : subsequentNodes) {
        workspaceNodeDAO.updateOrderNumber(subsequentNode, ++referenceOrderNumber);
    }
    return workspaceNode;
}
Also used : WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode)

Example 28 with WorkspaceNode

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

the class WorkspaceMaterialController method listWorkspaceFolders.

private List<WorkspaceNode> listWorkspaceFolders(WorkspaceEntity workspaceEntity, BooleanPredicate hidden) {
    List<WorkspaceNode> result = new ArrayList<>();
    WorkspaceRootFolder rootFolder = findWorkspaceRootFolderByWorkspaceEntity(workspaceEntity);
    result.add(rootFolder);
    appendChildFolders(rootFolder, result, hidden);
    return result;
}
Also used : ArrayList(java.util.ArrayList) WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode) WorkspaceRootFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder)

Example 29 with WorkspaceNode

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

the class WorkspaceMaterialController method deleteWorkspaceMaterial.

public void deleteWorkspaceMaterial(WorkspaceMaterial workspaceMaterial, boolean removeAnswers) throws WorkspaceMaterialContainsAnswersExeption {
    try {
        workspaceMaterialDeleteEvent.fire(new WorkspaceMaterialDeleteEvent(workspaceMaterial, removeAnswers));
        List<WorkspaceNode> childNodes = workspaceNodeDAO.listByParentSortByOrderNumber(workspaceMaterial);
        for (WorkspaceNode childNode : childNodes) {
            if (childNode instanceof WorkspaceMaterial) {
                deleteWorkspaceMaterial((WorkspaceMaterial) childNode, removeAnswers);
            } else if (childNode instanceof WorkspaceFolder) {
                deleteWorkspaceFolder((WorkspaceFolder) childNode);
            }
        }
    } catch (Exception e) {
        Throwable cause = e;
        while (cause != null) {
            cause = cause.getCause();
            if (cause instanceof WorkspaceMaterialContainsAnswersExeption) {
                throw (WorkspaceMaterialContainsAnswersExeption) cause;
            }
        }
        throw e;
    }
    workspaceMaterialDAO.delete(workspaceMaterial);
}
Also used : WorkspaceMaterialDeleteEvent(fi.otavanopisto.muikku.plugins.workspace.events.WorkspaceMaterialDeleteEvent) WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) SAXNotSupportedException(org.xml.sax.SAXNotSupportedException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) SAXException(org.xml.sax.SAXException) TransformerException(javax.xml.transform.TransformerException) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) WorkspaceFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder)

Example 30 with WorkspaceNode

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

the class WorkspaceMaterialUploadBackingBean method upload.

public String upload() {
    ObjectMapper objectMapper = new ObjectMapper();
    if (!sessionController.isLoggedIn()) {
        return "/error/internal-error.jsf";
    }
    // Workspace
    WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return "/error/internal-error.jsf";
    }
    WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceAndUserIdentifier(workspaceEntity, sessionController.getLoggedUser());
    if (workspaceUserEntity == null || workspaceUserEntity.getWorkspaceUserRole() == null || workspaceUserEntity.getWorkspaceUserRole().getArchetype() != WorkspaceRoleArchetype.TEACHER) {
        return "/error/internal-error.jsf";
    }
    WorkspaceNode parent = null;
    if (getFolderId() != null) {
        WorkspaceFolder workspaceFolder = workspaceMaterialController.findWorkspaceFolderById(getFolderId());
        if (workspaceFolder == null) {
            return "/error/internal-error.jsf";
        }
        WorkspaceRootFolder workspaceRootFolder = workspaceMaterialController.findWorkspaceRootFolderByWorkspaceNode(workspaceFolder);
        if (workspaceRootFolder == null) {
            return "/error/internal-error.jsf";
        }
        if (!workspaceRootFolder.getWorkspaceEntityId().equals(workspaceEntityId)) {
            return "/error/internal-error.jsf";
        }
    } else {
        parent = workspaceMaterialController.findWorkspaceRootFolderByWorkspaceEntity(workspaceEntity);
    }
    try {
        FileMeta[] fileMetas = objectMapper.readValue(getUploadMeta(), FileMeta[].class);
        for (FileMeta fileMeta : fileMetas) {
            String fileId = fileMeta.getId();
            try {
                String contentType = fileMeta.getContentType();
                String fileName = fileMeta.getName();
                byte[] fileData = TempFileUtils.getTempFileData(fileId);
                String license = null;
                BinaryMaterial binaryMaterial = binaryMaterialController.createBinaryMaterial(fileName, contentType, fileData, license);
                workspaceMaterialController.createWorkspaceMaterial(parent, binaryMaterial);
            } finally {
                TempFileUtils.deleteTempFile(fileId);
            }
        }
    } catch (IOException e) {
        logger.log(Level.SEVERE, "File uploading filed", e);
        return "/error/internal-error.jsf";
    }
    return null;
}
Also used : WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) BinaryMaterial(fi.otavanopisto.muikku.plugins.material.model.BinaryMaterial) IOException(java.io.IOException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode) WorkspaceFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder) WorkspaceRootFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder)

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