Search in sources :

Example 1 with WorkspaceFolder

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

the class WorkspaceRESTService method getWorkspaceFolder.

@GET
@Path("/workspaces/{WORKSPACEID}/folders/{WORKSPACEFOLDERID}")
@RESTPermitUnimplemented
public Response getWorkspaceFolder(@PathParam("WORKSPACEID") Long workspaceEntityId, @PathParam("WORKSPACEFOLDERID") Long workspaceFolderId) {
    // Workspace
    WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    // WorkspaceFolder
    WorkspaceFolder workspaceFolder = workspaceMaterialController.findWorkspaceFolderById(workspaceFolderId);
    if (workspaceFolder == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    return Response.ok(createRestModel(workspaceFolder)).build();
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder) Path(javax.ws.rs.Path) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented) GET(javax.ws.rs.GET)

Example 2 with WorkspaceFolder

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

the class WorkspaceRESTService method updateWorkspaceFolder.

@PUT
@Path("/workspaces/{WORKSPACEID}/folders/{WORKSPACEFOLDERID}")
@RESTPermitUnimplemented
public Response updateWorkspaceFolder(@PathParam("WORKSPACEID") Long workspaceEntityId, @PathParam("WORKSPACEFOLDERID") Long workspaceFolderId, fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceFolder restFolder) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.UNAUTHORIZED).entity("Not logged in").build();
    }
    if (restFolder == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    // Workspace
    WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    if (!sessionController.hasWorkspacePermission(MuikkuPermissions.MANAGE_WORKSPACE_MATERIALS, workspaceEntity)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    // WorkspaceFolder
    WorkspaceFolder workspaceFolder = workspaceMaterialController.findWorkspaceFolderById(restFolder.getId());
    if (workspaceFolder == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    // Workspace folder belongs to workspace check
    Long folderWorkspaceEntityId = workspaceMaterialController.getWorkspaceEntityId(workspaceFolder);
    if (!folderWorkspaceEntityId.equals(workspaceEntityId)) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    // Actual update
    WorkspaceNode parentNode = restFolder.getParentId() == null ? null : workspaceMaterialController.findWorkspaceNodeById(restFolder.getParentId());
    WorkspaceNode nextSibling = restFolder.getNextSiblingId() == null ? null : workspaceMaterialController.findWorkspaceNodeById(restFolder.getNextSiblingId());
    Boolean hidden = restFolder.getHidden();
    String title = restFolder.getTitle();
    MaterialViewRestrict viewRestrict = restFolder.getViewRestrict();
    workspaceFolder = workspaceMaterialController.updateWorkspaceFolder(workspaceFolder, title, parentNode, nextSibling, hidden, viewRestrict);
    return Response.ok(createRestModel(workspaceFolder)).build();
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) MaterialViewRestrict(fi.otavanopisto.muikku.plugins.material.model.MaterialViewRestrict) WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode) WorkspaceFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder) Path(javax.ws.rs.Path) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented) PUT(javax.ws.rs.PUT)

Example 3 with WorkspaceFolder

use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder 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 4 with WorkspaceFolder

use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder 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 5 with WorkspaceFolder

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

the class WorkspaceMaterialController method createWorkspaceFolder.

public WorkspaceFolder createWorkspaceFolder(WorkspaceNode parent, String title, String urlName, Integer index, Boolean hidden, WorkspaceFolderType folderType, MaterialViewRestrict viewRestrict) {
    WorkspaceFolder workspaceFolder = workspaceFolderDAO.create(parent, title, urlName, index, hidden, folderType, viewRestrict);
    workspaceFolderCreateEvent.fire(new WorkspaceFolderCreateEvent(workspaceFolder));
    return workspaceFolder;
}
Also used : WorkspaceFolderCreateEvent(fi.otavanopisto.muikku.plugins.workspace.events.WorkspaceFolderCreateEvent) WorkspaceFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder)

Aggregations

WorkspaceFolder (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder)20 WorkspaceNode (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode)11 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)6 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)6 HtmlMaterial (fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial)5 IOException (java.io.IOException)5 Path (javax.ws.rs.Path)5 RESTPermitUnimplemented (fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)4 ArrayList (java.util.ArrayList)4 DeusNexInternalException (fi.otavanopisto.muikku.plugins.dnm.parser.DeusNexInternalException)3 Resource (fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Resource)3 Material (fi.otavanopisto.muikku.plugins.material.model.Material)3 TransformerException (javax.xml.transform.TransformerException)3 XPathExpressionException (javax.xml.xpath.XPathExpressionException)3 SAXException (org.xml.sax.SAXException)3 DeusNexException (fi.otavanopisto.muikku.plugins.dnm.parser.DeusNexException)2 DeusNexDocument (fi.otavanopisto.muikku.plugins.dnm.parser.structure.DeusNexDocument)2 BinaryMaterial (fi.otavanopisto.muikku.plugins.material.model.BinaryMaterial)2 EntityManager (javax.persistence.EntityManager)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2