#928: EmployeeScriptingService.kt

projectforge-business/src/main/kotlin/org/projectforge/business/fibu/EmployeeScriptingService.kt Type: Scripting Proxy Service · Purpose: Read-only wrapper around EmployeeService for Groovy/Kotlin script access · Path: projectforge-business/src/main/kotlin/org/projectforge/business/fibu/EmployeeScriptingService.kt 198 lines · 66 code · 117 comments · 15 blank
Scripting proxy that wraps EmployeeService providing read-only access to employee business logic for Groovy/Kotlin scripts. Available in scripts as: employeeService. Exposes time-dependent attribute lookups, active-status checks, employee search, and monthly report generation. This is the newer, preferred scripting interface compared to EmployeeScriptingDao.

Architecture & Design

Delegation Pattern

Every method delegates directly to the underlying EmployeeService instance (constructor-injected as __employeeService). The proxy follows the same pattern as ScriptingDao but wraps a service instead of a DAO — providing business logic rather than just entity access.

Exposed Methods

MethodUnderlying Service CallPurpose
getWeeklyWorkingHours(employee)EmployeeService.getWeeklyWorkingHours(employee)Weekly hours valid today
getWeeklyWorkingHours(employee, validAtDate, checkAccess)EmployeeService.getWeeklyWorkingHours(employee, validAtDate, checkAccess)Weekly hours at historical date — CRITICAL for scripts needing historical data
getAnnualLeaveDays(employee)EmployeeService.getAnnualLeaveDays(employee)Annual leave valid today
getAnnualLeaveDays(employee, validAtDate, checkAccess)EmployeeService.getAnnualLeaveDays(employee, validAtDate, checkAccess)Annual leave at historical date
isEmployeeActive(employee, showRecentlyLeavers)EmployeeService.isEmployeeActive()Active-status check
getEmployeeStatus(employee, checkAccess)EmployeeService.getEmployeeStatus()Current EmployeeStatus enum
selectAllActive(checkAccess, showRecentLeft)EmployeeService.selectAllActive()All active employees
findByUserId(userId)EmployeeService.findByUserId()Lookup by user ID
findByStaffnumber(staffnumber)EmployeeService.findByStaffnumber()Lookup by staff number (Int and String overloads)
selectAllValidSinceAttrs(employee, type, deleted, checkAccess)EmployeeService.selectAllValidSinceAttrs()All time-dependent attributes with optional filtering
getReportOfMonth(year, month, user)EmployeeService.getReportOfMonth()Monthly employee report with aggregated timesheet data

Design Rationale

Scripts need access to business logic like "get weekly hours for employee at date X" or "is this employee active?" — not just CRUD. This proxy exposes only read-only methods. Scripts should never mutate data through this interface; mutations go through dedicated scripting DAOs.

Git History

8d821622d EmployeeScriptingService.getReportOfMonth
b589ea0c1 EmployeeScriptingService.kt: selectAllValidSinceAttrs added.
10d4e0aad Add EmployeeScriptingService for script access to employee data