Search in sources :

Example 1 with Subject

use of fi.otavanopisto.muikku.schooldata.entity.Subject in project muikku by otavanopisto.

the class WorkspaceIndexer method indexWorkspace.

private void indexWorkspace(Workspace workspace, WorkspaceEntity workspaceEntity) {
    try {
        Map<String, Object> extra = new HashMap<>();
        extra.put("published", workspaceEntity.getPublished());
        extra.put("access", workspaceEntity.getAccess());
        if (workspace.getSubjectIdentifier() != null) {
            Subject subject = courseMetaController.findSubject(workspace.getSchoolDataSource(), workspace.getSubjectIdentifier());
            extra.put("subject", subject.getName());
        }
        List<WorkspaceUser> staffMembers = workspaceController.listWorkspaceStaffMembers(workspaceEntity);
        Set<IndexedWorkspaceUser> indexedWorkspaceStaffMembers = new HashSet<IndexedWorkspaceUser>();
        for (WorkspaceUser staffMember : staffMembers) {
            // TODO: more efficient name fetching
            User staffMemberUser = userController.findUserByIdentifier(staffMember.getUserIdentifier());
            if (staffMemberUser != null) {
                indexedWorkspaceStaffMembers.add(new IndexedWorkspaceUser(staffMember.getUserIdentifier(), staffMemberUser.getFirstName(), staffMemberUser.getLastName()));
            } else {
                String userId = staffMember.getUserIdentifier() != null ? staffMember.getUserIdentifier().toId() : "NULL";
                logger.warning(String.format("Couldn't find staffmember #%s in workspace %s", userId, workspace.getIdentifier(), workspace.getSchoolDataSource()));
            }
        }
        extra.put("staffMembers", indexedWorkspaceStaffMembers);
        indexer.index(Workspace.class.getSimpleName(), workspace, extra);
    } catch (Exception e) {
        logger.warning(String.format("could not index workspace #%s/%s", workspace.getIdentifier(), workspace.getSchoolDataSource()));
    }
}
Also used : WorkspaceUser(fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser) User(fi.otavanopisto.muikku.schooldata.entity.User) HashMap(java.util.HashMap) Subject(fi.otavanopisto.muikku.schooldata.entity.Subject) WorkspaceUser(fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser) HashSet(java.util.HashSet) Workspace(fi.otavanopisto.muikku.schooldata.entity.Workspace)

Example 2 with Subject

use of fi.otavanopisto.muikku.schooldata.entity.Subject 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 3 with Subject

use of fi.otavanopisto.muikku.schooldata.entity.Subject in project muikku by otavanopisto.

the class TranscriptofRecordsRESTService method getVops.

@GET
@Path("/vops/{IDENTIFIER}")
@RESTPermit(handling = Handling.INLINE)
public Response getVops(@PathParam("IDENTIFIER") String studentIdentifierString) {
    String educationTypeMappingString = pluginSettingsController.getPluginSetting("transcriptofrecords", "educationTypeMapping");
    EducationTypeMapping educationTypeMapping = new EducationTypeMapping();
    if (educationTypeMappingString != null) {
        try {
            educationTypeMapping = new ObjectMapper().readValue(educationTypeMappingString, EducationTypeMapping.class);
        } catch (IOException e) {
            return Response.status(Status.INTERNAL_SERVER_ERROR).entity("Education type mapping not set").build();
        }
    }
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.FORBIDDEN).entity("Must be logged in").build();
    }
    SchoolDataIdentifier studentIdentifier = SchoolDataIdentifier.fromId(studentIdentifierString);
    if (studentIdentifier == null) {
        return Response.status(Status.NOT_FOUND).entity("Student identifier not found").build();
    }
    if (!sessionController.hasEnvironmentPermission(TranscriptofRecordsPermissions.TRANSCRIPT_OF_RECORDS_VIEW_ANY_STUDENT_STUDIES) && !Objects.equals(sessionController.getLoggedUser(), studentIdentifier)) {
        return Response.status(Status.FORBIDDEN).entity("Can only look at own information").build();
    }
    User student = userController.findUserByIdentifier(studentIdentifier);
    if (!vopsController.shouldShowStudies(student)) {
        VopsRESTModel result = new VopsRESTModel(null, 0, 0, false);
        return Response.ok(result).build();
    }
    List<TransferCredit> transferCredits = new ArrayList<>(gradingController.listStudentTransferCredits(studentIdentifier));
    List<Subject> subjects = courseMetaController.listSubjects();
    Map<SchoolDataIdentifier, WorkspaceAssessment> studentAssessments = vopsController.listStudentAssessments(studentIdentifier);
    String curriculum = pluginSettingsController.getPluginSetting("transcriptofrecords", "curriculum");
    SchoolDataIdentifier curriculumIdentifier = null;
    if (curriculum != null) {
        curriculumIdentifier = SchoolDataIdentifier.fromId(curriculum);
    }
    final List<String> subjectList = new ArrayList<String>();
    String commaSeparatedSubjectsOrder = pluginSettingsController.getPluginSetting("transcriptofrecords", "subjectsOrder");
    if (!StringUtils.isBlank(commaSeparatedSubjectsOrder)) {
        subjectList.addAll(Arrays.asList(commaSeparatedSubjectsOrder.split(",")));
    }
    subjects.sort(new Comparator<Subject>() {

        public int compare(Subject o1, Subject o2) {
            int i1 = subjectList.indexOf(o1.getCode());
            int i2 = subjectList.indexOf(o2.getCode());
            i1 = i1 == -1 ? Integer.MAX_VALUE : i1;
            i2 = i2 == -1 ? Integer.MAX_VALUE : i2;
            return i1 < i2 ? -1 : i1 == i2 ? 0 : 1;
        }
    });
    VopsLister lister = new VopsLister(subjects, vopsController, student, transferCredits, curriculumIdentifier, workspaceController, workspaceUserEntityController, studentIdentifier, studentAssessments, userGroupEntityController, permissionController, studiesViewCourseChoiceController, studentIdentifierString, gradingController, educationTypeMapping);
    lister.performListing();
    VopsRESTModel result = new VopsRESTModel(lister.getRows(), lister.getNumCourses(), lister.getNumMandatoryCourses(), lister.isOptedIn());
    return Response.ok(result).build();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) WorkspaceAssessment(fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment) User(fi.otavanopisto.muikku.schooldata.entity.User) EnvironmentUser(fi.otavanopisto.muikku.model.users.EnvironmentUser) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Subject(fi.otavanopisto.muikku.schooldata.entity.Subject) VopsLister(fi.otavanopisto.muikku.plugins.transcriptofrecords.VopsLister) TransferCredit(fi.otavanopisto.muikku.schooldata.entity.TransferCredit) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 4 with Subject

use of fi.otavanopisto.muikku.schooldata.entity.Subject in project muikku by otavanopisto.

the class VopsLister method performListing.

public void performListing() {
    for (Subject subject : subjects) {
        boolean subjectHasCourses = false;
        if (vopsController.subjectAppliesToStudent(student, subject)) {
            List<VopsRESTModel.VopsEntry> entries = new ArrayList<>();
            for (int courseNumber = 1; courseNumber <= MAX_COURSE_NUMBER; courseNumber++) {
                VopsRESTModel.VopsEntry entry = processCourse(subject, courseNumber);
                entries.add(entry);
                if (!(entry instanceof VopsRESTModel.VopsPlaceholder)) {
                    subjectHasCourses = true;
                }
            }
            if (subjectHasCourses) {
                rows.add(new VopsRESTModel.VopsRow(subject.getCode(), new SchoolDataIdentifier(subject.getIdentifier(), subject.getSchoolDataSource()).toId(), entries));
            }
        }
    }
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) VopsRow(fi.otavanopisto.muikku.plugins.transcriptofrecords.rest.VopsRESTModel.VopsRow) ArrayList(java.util.ArrayList) VopsRESTModel(fi.otavanopisto.muikku.plugins.transcriptofrecords.rest.VopsRESTModel) Subject(fi.otavanopisto.muikku.schooldata.entity.Subject)

Example 5 with Subject

use of fi.otavanopisto.muikku.schooldata.entity.Subject in project muikku by otavanopisto.

the class PyramusCourseMetaSchoolDataBridge method listCourseIdentifiers.

@Override
public List<CourseIdentifier> listCourseIdentifiers() {
    List<CourseIdentifier> result = new ArrayList<>();
    fi.otavanopisto.pyramus.rest.model.Subject[] subjects = pyramusClient.get("/common/subjects/", fi.otavanopisto.pyramus.rest.model.Subject[].class);
    if (subjects != null) {
        for (fi.otavanopisto.pyramus.rest.model.Subject subject : subjects) {
            List<String> courseNumbers = new ArrayList<String>();
            String identifier = subject.getId().toString();
            Course[] courses = pyramusClient.get("/common/subjects/" + identifier + "/courses", fi.otavanopisto.pyramus.rest.model.Course[].class);
            if (courses != null) {
                for (Course course : courses) {
                    String courseNumber = course.getCourseNumber() != null ? course.getCourseNumber().toString() : "null";
                    if (!courseNumbers.contains(courseNumber))
                        courseNumbers.add(courseNumber);
                }
                for (String cn : courseNumbers) {
                    result.add(new PyramusCourseIdentifier(subject.getId().toString() + "/" + cn, subject.getCode(), subject.getId().toString()));
                }
            }
        }
    }
    return result;
}
Also used : PyramusCourseIdentifier(fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusCourseIdentifier) ArrayList(java.util.ArrayList) PyramusCourseIdentifier(fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusCourseIdentifier) CourseIdentifier(fi.otavanopisto.muikku.schooldata.entity.CourseIdentifier) Subject(fi.otavanopisto.muikku.schooldata.entity.Subject) PyramusSubject(fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusSubject) Course(fi.otavanopisto.pyramus.rest.model.Course)

Aggregations

Subject (fi.otavanopisto.muikku.schooldata.entity.Subject)5 ArrayList (java.util.ArrayList)3 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)2 User (fi.otavanopisto.muikku.schooldata.entity.User)2 Workspace (fi.otavanopisto.muikku.schooldata.entity.Workspace)2 EnvironmentUser (fi.otavanopisto.muikku.model.users.EnvironmentUser)1 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)1 PyramusCourseIdentifier (fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusCourseIdentifier)1 PyramusSubject (fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusSubject)1 VopsLister (fi.otavanopisto.muikku.plugins.transcriptofrecords.VopsLister)1 VopsRESTModel (fi.otavanopisto.muikku.plugins.transcriptofrecords.rest.VopsRESTModel)1 VopsRow (fi.otavanopisto.muikku.plugins.transcriptofrecords.rest.VopsRESTModel.VopsRow)1 WorkspaceEntityFile (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceEntityFile)1 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)1 CourseIdentifier (fi.otavanopisto.muikku.schooldata.entity.CourseIdentifier)1 CourseLengthUnit (fi.otavanopisto.muikku.schooldata.entity.CourseLengthUnit)1 EducationType (fi.otavanopisto.muikku.schooldata.entity.EducationType)1 TransferCredit (fi.otavanopisto.muikku.schooldata.entity.TransferCredit)1 WorkspaceAssessment (fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment)1 WorkspaceType (fi.otavanopisto.muikku.schooldata.entity.WorkspaceType)1