Search in sources :

Example 11 with WorkspaceFolder

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

the class WorkspaceRESTService method createWorkspaceFolder.

@POST
@Path("/workspaces/{WORKSPACEID}/folders/")
@RESTPermitUnimplemented
public Response createWorkspaceFolder(@PathParam("WORKSPACEID") Long workspaceEntityId, 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();
    }
    WorkspaceNode rootFolder = workspaceMaterialController.findWorkspaceRootFolderByWorkspaceEntity(workspaceEntity);
    WorkspaceNode nextSibling = restFolder.getNextSiblingId() == null ? null : workspaceMaterialController.findWorkspaceNodeById(restFolder.getNextSiblingId());
    WorkspaceFolder workspaceFolder = workspaceMaterialController.createWorkspaceFolder(rootFolder, "Untitled");
    if (nextSibling != null) {
        workspaceMaterialController.moveAbove(workspaceFolder, nextSibling);
    }
    return Response.ok(createRestModel(workspaceFolder)).build();
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode) WorkspaceFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)

Example 12 with WorkspaceFolder

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

the class WorkspaceMaterialController method ensureWorkspaceHelpPageExists.

public WorkspaceMaterial ensureWorkspaceHelpPageExists(WorkspaceEntity workspace) {
    WorkspaceFolder helpPageFolder = findWorkspaceHelpPageFolder(workspace);
    if (helpPageFolder == null) {
        helpPageFolder = createWorkspaceHelpPageFolder(workspace);
    }
    WorkspaceMaterial helpPageMaterial = null;
    List<WorkspaceMaterial> helpPageMaterials = listWorkspaceMaterialsByParent(helpPageFolder);
    if (helpPageMaterials.isEmpty()) {
        String title = localeController.getText(sessionController.getLocale(), "plugin.workspace.helpPage.title");
        String license = null;
        HtmlMaterial htmlMaterial = htmlMaterialController.createHtmlMaterial(title, "", "text/html", 0l, license);
        helpPageMaterial = createWorkspaceMaterial(helpPageFolder, htmlMaterial);
    } else {
        helpPageMaterial = helpPageMaterials.get(0);
    }
    return helpPageMaterial;
}
Also used : HtmlMaterial(fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) WorkspaceFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder)

Example 13 with WorkspaceFolder

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

the class WorkspaceMaterialController method appendChildFolders.

private void appendChildFolders(WorkspaceNode parent, List<WorkspaceNode> result, BooleanPredicate hidden) {
    List<WorkspaceFolder> childFolders = workspaceFolderDAO.listByHiddenAndParentAndFolderType(hidden, parent, WorkspaceFolderType.DEFAULT);
    result.addAll(childFolders);
    for (WorkspaceFolder childFolder : childFolders) {
        appendChildFolders(childFolder, result, hidden);
    }
}
Also used : WorkspaceFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder)

Example 14 with WorkspaceFolder

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

the class WorkspaceMaterialController method ensureWorkspaceFrontPageExists.

public WorkspaceMaterial ensureWorkspaceFrontPageExists(WorkspaceEntity workspace) {
    WorkspaceFolder frontPageFolder = findWorkspaceFrontPageFolder(workspace);
    if (frontPageFolder == null) {
        frontPageFolder = createWorkspaceFrontPageFolder(workspace);
    }
    WorkspaceMaterial frontPageMaterial = null;
    List<WorkspaceMaterial> frontPageMaterials = listWorkspaceMaterialsByParent(frontPageFolder);
    if (frontPageMaterials.isEmpty()) {
        String title = localeController.getText(sessionController.getLocale(), "plugin.workspace.frontPage.title");
        String license = null;
        HtmlMaterial htmlMaterial = htmlMaterialController.createHtmlMaterial(title, "", "text/html", 0l, license);
        frontPageMaterial = createWorkspaceMaterial(frontPageFolder, htmlMaterial);
    } else {
        frontPageMaterial = frontPageMaterials.get(0);
    }
    return frontPageMaterial;
}
Also used : HtmlMaterial(fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) WorkspaceFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder)

Example 15 with WorkspaceFolder

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

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