Search in sources :

Example 1 with WorkspaceType

use of fi.otavanopisto.muikku.schooldata.entity.WorkspaceType 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)

Aggregations

WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)1 WorkspaceEntityFile (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceEntityFile)1 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)1 CourseLengthUnit (fi.otavanopisto.muikku.schooldata.entity.CourseLengthUnit)1 EducationType (fi.otavanopisto.muikku.schooldata.entity.EducationType)1 Subject (fi.otavanopisto.muikku.schooldata.entity.Subject)1 Workspace (fi.otavanopisto.muikku.schooldata.entity.Workspace)1 WorkspaceType (fi.otavanopisto.muikku.schooldata.entity.WorkspaceType)1 RequestAction (org.ocpsoft.rewrite.annotation.RequestAction)1