Search in sources :

Example 46 with WorkspaceMaterial

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

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

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

the class WorkspaceMaterialController method listVisibleEvaluableWorkspaceMaterialsAsContentNodes.

public List<ContentNode> listVisibleEvaluableWorkspaceMaterialsAsContentNodes(WorkspaceEntity workspaceEntity, boolean processHtml) throws WorkspaceMaterialException {
    List<ContentNode> result = new ArrayList<>();
    List<WorkspaceMaterial> workspaceMaterials = listVisibleWorkspaceMaterialsByAssignmentType(workspaceEntity, WorkspaceMaterialAssignmentType.EVALUATED);
    for (WorkspaceMaterial workspaceMaterial : workspaceMaterials) {
        result.add(createContentNode(workspaceMaterial, 0, processHtml, false));
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)

Example 49 with WorkspaceMaterial

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

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

the class WorkspaceHelpPageBackingBean method init.

@RequestAction
public String init() {
    String urlName = getWorkspaceUrlName();
    if (StringUtils.isBlank(urlName)) {
        return NavigationRules.NOT_FOUND;
    }
    WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityByUrlName(urlName);
    if (workspaceEntity == null) {
        return NavigationRules.NOT_FOUND;
    }
    workspaceEntityId = workspaceEntity.getId();
    try {
        WorkspaceMaterial helpPage = workspaceMaterialController.ensureWorkspaceHelpPageExists(workspaceEntity);
        contentNodes = Arrays.asList(workspaceMaterialController.createContentNode(helpPage));
    } catch (WorkspaceMaterialException e) {
        logger.log(Level.SEVERE, "Error loading materials", e);
        return NavigationRules.INTERNAL_ERROR;
    }
    workspaceId = workspaceEntity.getId();
    workspaceBackingBean.setWorkspaceUrlName(urlName);
    workspaceName = workspaceBackingBean.getWorkspaceName();
    materialsBaseUrl = String.format("/workspace/%s/materials", workspaceUrlName);
    return null;
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) RequestAction(org.ocpsoft.rewrite.annotation.RequestAction)

Aggregations

WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)66 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)24 Path (javax.ws.rs.Path)24 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)18 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)17 HtmlMaterial (fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial)16 WorkspaceNode (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode)15 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)14 WorkspaceRootFolder (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder)14 GET (javax.ws.rs.GET)14 Material (fi.otavanopisto.muikku.plugins.material.model.Material)13 ArrayList (java.util.ArrayList)11 RESTPermitUnimplemented (fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)7 WorkspaceMaterialEvaluation (fi.otavanopisto.muikku.plugins.evaluation.model.WorkspaceMaterialEvaluation)6 BinaryMaterial (fi.otavanopisto.muikku.plugins.material.model.BinaryMaterial)6 WorkspaceFolder (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder)6 WorkspaceMaterialReply (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialReply)6 POST (javax.ws.rs.POST)6 SupplementationRequest (fi.otavanopisto.muikku.plugins.evaluation.model.SupplementationRequest)5 RestSupplementationRequest (fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestSupplementationRequest)5