Search in sources :

Example 1 with RequestAction

use of org.ocpsoft.rewrite.annotation.RequestAction in project muikku by otavanopisto.

the class WorkspaceAnnouncementsViewBackingBean 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;
    }
    if (!workspaceEntity.getPublished()) {
        if (!sessionController.hasWorkspacePermission(MuikkuPermissions.ACCESS_UNPUBLISHED_WORKSPACE, workspaceEntity)) {
            return NavigationRules.NOT_FOUND;
        }
    }
    if (workspaceEntity.getAccess() != WorkspaceAccess.ANYONE) {
        if (!sessionController.hasWorkspacePermission(AnnouncerPermissions.LIST_WORKSPACE_ANNOUNCEMENTS, workspaceEntity)) {
            if (!sessionController.isLoggedIn()) {
                return navigationController.requireLogin();
            } else {
                return NavigationRules.ACCESS_DENIED;
            }
        }
    }
    workspaceEntityId = workspaceEntity.getId();
    workspaceBackingBean.setWorkspaceUrlName(urlName);
    workspaceName = workspaceBackingBean.getWorkspaceName();
    workspaceNameExtension = workspaceBackingBean.getWorkspaceNameExtension();
    if (announcementId != null) {
        currentAnnouncement = announcementController.findById(announcementId);
    }
    activeAnnouncements = announcementController.listActiveByWorkspaceEntities(Collections.singletonList(workspaceEntity));
    return null;
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) RequestAction(org.ocpsoft.rewrite.annotation.RequestAction)

Example 2 with RequestAction

use of org.ocpsoft.rewrite.annotation.RequestAction in project muikku by otavanopisto.

the class TranscriptofRecordsBackingBean method init.

@RequestAction
public String init() {
    if (!sessionController.hasEnvironmentPermission(TranscriptofRecordsPermissions.TRANSCRIPT_OF_RECORDS_VIEW)) {
        return NavigationRules.ACCESS_DENIED;
    }
    Map<String, Grade> grades = new HashMap<>();
    List<GradingScale> gradingScales = gradingController.listGradingScales();
    for (GradingScale gradingScale : gradingScales) {
        List<GradingScaleItem> scaleItems = gradingController.listGradingScaleItems(gradingScale);
        for (GradingScaleItem scaleItem : scaleItems) {
            String id = StringUtils.join(new String[] { gradingScale.getSchoolDataSource(), gradingScale.getIdentifier(), scaleItem.getSchoolDataSource(), scaleItem.getIdentifier() }, '-');
            String grade = scaleItem.getName();
            String scale = gradingScale.getName();
            Boolean passing = scaleItem.isPassingGrade();
            grades.put(id, new Grade(grade, scale, passing));
        }
    }
    try {
        this.grades = new ObjectMapper().writeValueAsString(grades);
    } catch (JsonProcessingException e) {
        logger.log(Level.SEVERE, "Failed to serialize grades", e);
        return NavigationRules.INTERNAL_ERROR;
    }
    UserEntity loggedEntity = sessionController.getLoggedUserEntity();
    User user = userController.findUserByDataSourceAndIdentifier(sessionController.getLoggedUserSchoolDataSource(), sessionController.getLoggedUserIdentifier());
    studyStartDate = user.getStudyStartDate();
    studyTimeEnd = user.getStudyTimeEnd();
    studyTimeLeftStr = "";
    if (studyTimeEnd != null) {
        OffsetDateTime now = OffsetDateTime.now();
        Locale locale = sessionController.getLocale();
        if (now.isBefore(studyTimeEnd)) {
            long studyTimeLeftYears = now.until(studyTimeEnd, ChronoUnit.YEARS);
            now = now.plusYears(studyTimeLeftYears);
            if (studyTimeLeftYears > 0) {
                studyTimeLeftStr += studyTimeLeftYears + " " + localeController.getText(locale, "plugin.records.studyTimeEndShort.y");
            }
            long studyTimeLeftMonths = now.until(studyTimeEnd, ChronoUnit.MONTHS);
            now = now.plusMonths(studyTimeLeftMonths);
            if (studyTimeLeftMonths > 0) {
                if (studyTimeLeftStr.length() > 0)
                    studyTimeLeftStr += " ";
                studyTimeLeftStr += studyTimeLeftMonths + " " + localeController.getText(locale, "plugin.records.studyTimeEndShort.m");
            }
            long studyTimeLeftDays = now.until(studyTimeEnd, ChronoUnit.DAYS);
            now = now.plusDays(studyTimeLeftDays);
            if (studyTimeLeftDays > 0) {
                if (studyTimeLeftStr.length() > 0)
                    studyTimeLeftStr += " ";
                studyTimeLeftStr += studyTimeLeftDays + " " + localeController.getText(locale, "plugin.records.studyTimeEndShort.d");
            }
        }
    }
    List<TranscriptOfRecordsFile> transcriptOfRecordsFiles;
    if (loggedEntity != null) {
        transcriptOfRecordsFiles = transcriptOfRecordsFileController.listFiles(loggedEntity);
    } else {
        transcriptOfRecordsFiles = Collections.emptyList();
    }
    try {
        files = new ObjectMapper().writeValueAsString(transcriptOfRecordsFiles);
    } catch (JsonProcessingException e) {
        logger.log(Level.SEVERE, "Failed to serialize files", e);
        return NavigationRules.INTERNAL_ERROR;
    }
    return null;
}
Also used : Locale(java.util.Locale) GradingScale(fi.otavanopisto.muikku.schooldata.entity.GradingScale) User(fi.otavanopisto.muikku.schooldata.entity.User) HashMap(java.util.HashMap) GradingScaleItem(fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) OffsetDateTime(java.time.OffsetDateTime) TranscriptOfRecordsFile(fi.otavanopisto.muikku.plugins.transcriptofrecords.model.TranscriptOfRecordsFile) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RequestAction(org.ocpsoft.rewrite.annotation.RequestAction)

Example 3 with RequestAction

use of org.ocpsoft.rewrite.annotation.RequestAction in project muikku by otavanopisto.

the class SystemReindexBackingBean method init.

@RequestAction
public String init() {
    if (sessionController.hasPermission(MuikkuPermissions.ADMIN, null)) {
        List<Task> tasks = null;
        if (StringUtils.isNotBlank(getTask())) {
            Task task = EnumUtils.getEnum(Task.class, getTask());
            if (task == null) {
                return NavigationRules.INTERNAL_ERROR;
            } else {
                tasks = Arrays.asList(task);
            }
        } else {
            tasks = Arrays.asList(Task.values());
        }
        reindexEvent.fire(new SearchReindexEvent(tasks, resume != null ? resume : false));
    }
    return "/index.jsf?faces-redirect=true";
}
Also used : Task(fi.otavanopisto.muikku.search.SearchReindexEvent.Task) SearchReindexEvent(fi.otavanopisto.muikku.search.SearchReindexEvent) RequestAction(org.ocpsoft.rewrite.annotation.RequestAction)

Example 4 with RequestAction

use of org.ocpsoft.rewrite.annotation.RequestAction in project muikku by otavanopisto.

the class WorkspaceMaterialsManagementBackingBean 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;
    }
    if (!sessionController.hasWorkspacePermission(MuikkuPermissions.MANAGE_WORKSPACE_MATERIALS, workspaceEntity)) {
        return NavigationRules.ACCESS_DENIED;
    }
    rootFolder = workspaceMaterialController.findWorkspaceRootFolderByWorkspaceEntity(workspaceEntity);
    workspaceEntityId = workspaceEntity.getId();
    workspaceBackingBean.setWorkspaceUrlName(urlName);
    workspaceName = workspaceBackingBean.getWorkspaceName();
    try {
        contentNodes = workspaceMaterialController.listWorkspaceMaterialsAsContentNodes(workspaceEntity, true);
    } catch (WorkspaceMaterialException e) {
        logger.log(Level.SEVERE, "Error loading materials", e);
        return NavigationRules.INTERNAL_ERROR;
    }
    materialsBaseUrl = String.format("/workspace/%s/materials", workspaceUrlName);
    return null;
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) RequestAction(org.ocpsoft.rewrite.annotation.RequestAction)

Example 5 with RequestAction

use of org.ocpsoft.rewrite.annotation.RequestAction 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

RequestAction (org.ocpsoft.rewrite.annotation.RequestAction)27 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)19 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)5 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Permission (fi.otavanopisto.muikku.model.security.Permission)3 HashMap (java.util.HashMap)3 EnvironmentRoleEntity (fi.otavanopisto.muikku.model.users.EnvironmentRoleEntity)2 RoleEntity (fi.otavanopisto.muikku.model.users.RoleEntity)2 SystemRoleEntity (fi.otavanopisto.muikku.model.users.SystemRoleEntity)2 WorkspaceEntityFile (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceEntityFile)2 User (fi.otavanopisto.muikku.schooldata.entity.User)2 Workspace (fi.otavanopisto.muikku.schooldata.entity.Workspace)2 OffsetDateTime (java.time.OffsetDateTime)2 Locale (java.util.Locale)2 AuthenticationProvider (fi.otavanopisto.muikku.auth.AuthenticationProvider)1 AuthenticationResult (fi.otavanopisto.muikku.auth.AuthenticationResult)1 CacheFlushEvent (fi.otavanopisto.muikku.cache.CacheFlushEvent)1 AuthSource (fi.otavanopisto.muikku.model.security.AuthSource)1