Search in sources :

Example 6 with WorkspaceMaterial

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

the class WorkspaceHtmlMaterialDeleteListener method onHtmlMaterialDelete.

public void onHtmlMaterialDelete(@Observes HtmlMaterialDeleteEvent htmlMaterialDeleteEvent) throws WorkspaceMaterialContainsAnswersExeption {
    // TODO: This should not be limited to html materials
    Material material = htmlMaterialDeleteEvent.getMaterial();
    List<WorkspaceMaterial> workspaceMaterials = workspaceMaterialController.listWorkspaceMaterialsByMaterial(material);
    for (WorkspaceMaterial workspaceMaterial : workspaceMaterials) {
        workspaceMaterialController.deleteWorkspaceMaterial(workspaceMaterial, htmlMaterialDeleteEvent.getRemoveAnswers());
    }
}
Also used : Material(fi.otavanopisto.muikku.plugins.material.model.Material) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)

Example 7 with WorkspaceMaterial

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

the class WorkspaceIndexBackingBean 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;
    }
    canPublish = sessionController.hasWorkspacePermission(MuikkuPermissions.PUBLISH_WORKSPACE, workspaceEntity);
    workspaceEntityId = workspaceEntity.getId();
    published = workspaceEntity.getPublished();
    if (!published) {
        if (!sessionController.hasWorkspacePermission(MuikkuPermissions.ACCESS_UNPUBLISHED_WORKSPACE, workspaceEntity)) {
            return NavigationRules.NOT_FOUND;
        }
    }
    try {
        WorkspaceMaterial frontPage = workspaceMaterialController.ensureWorkspaceFrontPageExists(workspaceEntity);
        contentNodes = Arrays.asList(workspaceMaterialController.createContentNode(frontPage));
    } catch (WorkspaceMaterialException e) {
        logger.log(Level.SEVERE, "Error loading materials", e);
        return NavigationRules.INTERNAL_ERROR;
    }
    workspaceBackingBean.setWorkspaceUrlName(urlName);
    schoolDataBridgeSessionController.startSystemSession();
    try {
        Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
        if (workspace == null) {
            logger.warning(String.format("Could not find workspace for workspaceEntity #%d", workspaceEntity.getId()));
            return NavigationRules.NOT_FOUND;
        }
        WorkspaceType workspaceType = workspaceController.findWorkspaceType(workspace.getWorkspaceTypeId());
        EducationType educationTypeObject = workspace.getEducationTypeIdentifier() == null ? null : courseMetaController.findEducationType(workspace.getEducationTypeIdentifier());
        Subject subjectObject = courseMetaController.findSubject(workspace.getSchoolDataSource(), workspace.getSubjectIdentifier());
        CourseLengthUnit lengthUnit = null;
        if ((workspace.getLength() != null) && (workspace.getLengthUnitIdentifier() != null)) {
            lengthUnit = courseMetaController.findCourseLengthUnit(workspace.getSchoolDataSource(), workspace.getLengthUnitIdentifier());
        }
        workspaceId = workspaceEntity.getId();
        workspaceName = workspace.getName();
        workspaceNameExtension = workspace.getNameExtension();
        subject = subjectObject != null ? subjectObject.getName() : null;
        educationType = educationTypeObject != null ? educationTypeObject.getName() : null;
        if (lengthUnit != null) {
            courseLength = workspace.getLength();
            courseLengthSymbol = lengthUnit.getSymbol();
        }
        beginDate = workspace.getBeginDate() != null ? Date.from(workspace.getBeginDate().toInstant()) : null;
        endDate = workspace.getEndDate() != null ? Date.from(workspace.getEndDate().toInstant()) : null;
        if (workspaceType != null) {
            this.workspaceType = workspaceType.getName();
        }
    } finally {
        schoolDataBridgeSessionController.endSystemSession();
    }
    WorkspaceEntityFile customFrontImage = workspaceEntityFileController.findWorkspaceEntityFile(workspaceEntity, "workspace-frontpage-image-cropped");
    hasCustomFrontPageImage = customFrontImage != null;
    customFrontPageImageUrl = hasCustomFrontPageImage ? String.format("/rest/workspace/workspaces/%d/workspacefile/workspace-frontpage-image-cropped", workspaceEntity.getId()) : null;
    materialsBaseUrl = String.format("/workspace/%s/materials", workspaceUrlName);
    announcementsBaseUrl = String.format("/workspace/%s/announcements", workspaceUrlName);
    workspaceVisitController.visit(workspaceEntity);
    return null;
}
Also used : WorkspaceType(fi.otavanopisto.muikku.schooldata.entity.WorkspaceType) WorkspaceEntityFile(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceEntityFile) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) EducationType(fi.otavanopisto.muikku.schooldata.entity.EducationType) CourseLengthUnit(fi.otavanopisto.muikku.schooldata.entity.CourseLengthUnit) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) Subject(fi.otavanopisto.muikku.schooldata.entity.Subject) Workspace(fi.otavanopisto.muikku.schooldata.entity.Workspace) RequestAction(org.ocpsoft.rewrite.annotation.RequestAction)

Example 8 with WorkspaceMaterial

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

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

the class WorkspaceMaterialController method revertToOriginMaterial.

public WorkspaceMaterial revertToOriginMaterial(WorkspaceMaterial workspaceMaterial, boolean updateUrlName) {
    Material originMaterial = getMaterialForWorkspaceMaterial(workspaceMaterial).getOriginMaterial();
    if (originMaterial == null) {
        throw new IllegalArgumentException("WorkSpaceMaterial has no origin material");
    }
    workspaceMaterialDAO.updateMaterialId(workspaceMaterial, originMaterial.getId());
    if (updateUrlName) {
        String urlName = generateUniqueUrlName(workspaceMaterial.getParent(), workspaceMaterial, originMaterial.getTitle());
        if (!workspaceMaterial.getUrlName().equals(urlName)) {
            workspaceMaterialDAO.updateUrlName(workspaceMaterial, urlName);
        }
    }
    return workspaceMaterial;
}
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)

Example 10 with WorkspaceMaterial

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

the class WorkspaceMaterialController method createWorkspaceMaterial.

public WorkspaceMaterial createWorkspaceMaterial(WorkspaceNode parent, Material material, String title, String urlName, Integer index, Boolean hidden, WorkspaceMaterialAssignmentType assignmentType, WorkspaceMaterialCorrectAnswersDisplay correctAnswers) {
    WorkspaceMaterial workspaceMaterial = workspaceMaterialDAO.create(parent, material.getId(), title, urlName, index, hidden, assignmentType, correctAnswers);
    workspaceMaterialCreateEvent.fire(new WorkspaceMaterialCreateEvent(workspaceMaterial));
    return workspaceMaterial;
}
Also used : WorkspaceMaterialCreateEvent(fi.otavanopisto.muikku.plugins.workspace.events.WorkspaceMaterialCreateEvent) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)

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