Skip to content

Commit

Permalink
Merge pull request #4644 from UniversityOfHelsinkiCS/OOD-59
Browse files Browse the repository at this point in the history
OOD-59: [updater] [backend] try-catch-clauses for updates and if-clauses for using HY-specific programmeCode-map
  • Loading branch information
valtterikantanen authored Oct 8, 2024
2 parents 4d712a3 + 52a8cd2 commit d9e1943
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 36 deletions.
5 changes: 4 additions & 1 deletion services/backend/src/services/faculty/faculty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { groupBy, orderBy } from 'lodash'
import moment from 'moment'
import { InferAttributes, QueryTypes } from 'sequelize'

import { serviceProvider } from '../../config'
import { programmeCodes } from '../../config/programmeCodes'
import { dbConnections } from '../../database/connection'
import { Organization, ProgrammeModule } from '../../models'
Expand Down Expand Up @@ -54,7 +55,9 @@ export const getDegreeProgrammesOfOrganization = async (organizationId: string,
const programmesWithProgIds = programmesOfOrganization.map(programme => ({
...programme,
progId:
programme.code in programmeCodes ? programmeCodes[programme.code as keyof typeof programmeCodes] : programme.code,
programme.code in programmeCodes && serviceProvider !== 'fd'
? programmeCodes[programme.code as keyof typeof programmeCodes]
: programme.code,
}))
const programmesGroupedByCode = groupBy(orderBy(programmesWithProgIds, ['valid_from'], ['desc']), prog => prog.code)
const curriculumPeriods = await getCurriculumPeriods()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,10 @@ export const tableTitles = {
studytracksEnd: ['Men', 'Women', 'Other/\nUnknown', 'Finland', 'Other'],
} as const

export const getId = (code: string) =>
code in programmeCodes ? programmeCodes[code as keyof typeof programmeCodes] : ''
export const getId = (code: string) => {
if (serviceProvider !== 'fd') return code in programmeCodes ? programmeCodes[code as keyof typeof programmeCodes] : ''
return code
}

export const getGoal = (programme?: string) => {
if (!programme) return 0
Expand Down
28 changes: 17 additions & 11 deletions updater/sis-updater-worker/src/updater/updateMeta.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {
Organization,
StudyrightExtent,
} = require('../db/models')
const { logger } = require('../utils/logger')
const {
courseMapper,
courseProviderMapper,
Expand Down Expand Up @@ -70,18 +71,23 @@ const updateCourses = async (courseIdToAttainments, groupIdToCourse) => {
if (!courseUnitOrganisations) {
continue
}
for (const { share, organisationId, roleUrn, validityPeriod = {} } of courseUnitOrganisations) {
const effectiveValidityPeriod = Object.keys(validityPeriod).length ? validityPeriod : courseUnitValidityPeriod
const shareObj = {
share,
...(effectiveValidityPeriod.startDate && { startDate: effectiveValidityPeriod.startDate }),
...(effectiveValidityPeriod.endDate && { endDate: effectiveValidityPeriod.endDate }),
}

if (!organisationsById[organisationId]) {
organisationsById[organisationId] = { organisationId, roleUrn, shares: [shareObj] }
} else {
organisationsById[organisationId].shares.push(shareObj)
for (const { share, organisationId, roleUrn, validityPeriod = {} } of courseUnitOrganisations) {
try {
const effectiveValidityPeriod = Object.keys(validityPeriod).length ? validityPeriod : courseUnitValidityPeriod
const shareObj = {
share,
...(effectiveValidityPeriod.startDate && { startDate: effectiveValidityPeriod.startDate }),
...(effectiveValidityPeriod.endDate && { endDate: effectiveValidityPeriod.endDate }),
}

if (!organisationsById[organisationId]) {
organisationsById[organisationId] = { organisationId, roleUrn, shares: [shareObj] }
} else {
organisationsById[organisationId].shares.push(shareObj)
}
} catch (error) {
logger.error(`Error in course unit organisation handling for orgId ${organisationId}`)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { serviceProvider } = require('../../config')

const anyModule = rule => ({ id: rule.localId, name: 'Any module' })
const anyCourse = rule => ({ id: rule.localId, name: 'Any course' })
const unknownRule = rule => ({ type: rule.type, fact: 'Unhandled rule' })
Expand Down Expand Up @@ -73,7 +75,7 @@ class ModuleResolver {
const children = []

for (const mod of modules) {
if (mod.code?.startsWith('KK-')) continue
if (serviceProvider !== 'fd' && mod.code?.startsWith('KK-')) continue
let result = this.moduleCache[mod.id]
if (!result) {
result = await this.resolveSingleModule(mod)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { chunk } = require('lodash')
const { bulkCreate, selectFromByIds } = require('../../db')
const { dbConnections } = require('../../db/connection')
const { ProgrammeModule, ProgrammeModuleChild } = require('../../db/models')
const { logger } = require('../../utils/logger')
const ModuleResolver = require('./resolver')

const resolveProgramme = async programme => {
Expand Down Expand Up @@ -56,7 +57,14 @@ const recursiveWrite = (modArg, parentId, programmeMap, joinMap) => {
if (parentId) joinMap[join.composite] = join

if (!children) return
children.forEach(child => recursiveWrite(child, mod.id, programmeMap, joinMap))
try {
children.forEach(child => recursiveWrite(child, mod.id, programmeMap, joinMap))
} catch (error) {
logger.error(
`Could not update programme module with id ${mod.id} and parentId ${parentId} due to faulty children/rule handling`,
error
)
}
}

const updateProgrammeModulesChunk = async programmeIds => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { selectAllFrom, bulkCreate, selectOneById } = require('../../db')
const { SISStudyRight, SISStudyRightElement } = require('../../db/models')
const { logger } = require('../../utils')
const { termRegistrationTypeToEnrollmenttype } = require('../mapper')
const {
getEducation,
Expand Down Expand Up @@ -38,28 +39,33 @@ const getStudyRightSemesterEnrollments = semesterEnrollments => {
}

const studyRightMapper = (personIdToStudentNumber, admissionNamesById, semesterEnrollments) => studyRight => {
const semesterEnrollmentsForStudyRight = semesterEnrollments.find(
({ study_right_id }) => study_right_id === studyRight.id
)?.term_registrations
const studyRightEducation = getEducation(studyRight.education_id)
if (!studyRightEducation) return null
try {
const semesterEnrollmentsForStudyRight = semesterEnrollments.find(
({ study_right_id }) => study_right_id === studyRight.id
)?.term_registrations
const studyRightEducation = getEducation(studyRight.education_id)
if (!studyRightEducation) return null

const educationType = getEducationType(studyRightEducation.education_type)
const extentCode = educationTypeToExtentcode[educationType.id] || educationTypeToExtentcode[educationType.parent_id]
const educationType = getEducationType(studyRightEducation.education_type)
const extentCode = educationTypeToExtentcode[educationType.id] || educationTypeToExtentcode[educationType.parent_id]

return {
id: studyRight.id,
// validityPeriod of a study right always has a start date but not always an end date. The interval is end exclusive so we need to subtract one day from the end date to get the "real" end date.
startDate: new Date(studyRight.valid.startDate),
endDate: addDaysToDate(studyRight.valid.endDate, -1),
studyStartDate: studyRight.study_start_date ? new Date(studyRight.study_start_date) : null,
// cancellationType is always 'RESCINDED' or 'CANCELLED_BY_ADMINISTRATION'
cancelled: studyRight.study_right_cancellation != null,
studentNumber: personIdToStudentNumber[studyRight.person_id],
extentCode,
admissionType: admissionNamesById[studyRight.admission_type_urn],
semesterEnrollments: getStudyRightSemesterEnrollments(semesterEnrollmentsForStudyRight),
facultyCode: getOrganisationCode(studyRight.organisation_id),
return {
id: studyRight.id,
// validityPeriod of a study right always has a start date but not always an end date. The interval is end exclusive so we need to subtract one day from the end date to get the "real" end date.
startDate: new Date(studyRight.valid.startDate),
endDate: addDaysToDate(studyRight.valid.endDate, -1),
studyStartDate: studyRight.study_start_date ? new Date(studyRight.study_start_date) : null,
// cancellationType is always 'RESCINDED' or 'CANCELLED_BY_ADMINISTRATION'
cancelled: studyRight.study_right_cancellation != null,
studentNumber: personIdToStudentNumber[studyRight.person_id],
extentCode,
admissionType: admissionNamesById[studyRight.admission_type_urn],
semesterEnrollments: getStudyRightSemesterEnrollments(semesterEnrollmentsForStudyRight),
facultyCode: getOrganisationCode(studyRight.organisation_id),
}
} catch (error) {
logger.error(`Study right mapping failed for studyRightId ${studyRight.id}`, error)
return null
}
}

Expand Down

0 comments on commit d9e1943

Please sign in to comment.