#858: BookType.kt

projectforge-business/src/main/kotlin/org/projectforge/business/book/BookType.kt Type: Kotlin Enum (implements I18nEnum)
Purpose: Categorises bibliographic entries in the book-management module
Location: projectforge-business/src/main/kotlin/org/projectforge/business/book/BookType.kt 51 lines · 18 code · 29 comments · 4 blank
Summary: BookType is a straightforward enumeration of media types supported by ProjectForge's book-management feature. It implements I18nEnum so that each value's label (e.g. "Audio Book", "E-Book", "Magazine") can be localised. The enum covers both traditional bibliographic categories (book, thesis) and modern digital media (ebook, software, film).

Enum Values

Enum ConstantKeyi18n PropertyTypical Use
AUDIO_BOOKaudiobookbook.type.audiobookSpoken-word recordings
BOOKbookbook.type.bookStandard printed book (default)
EBOOKebookbook.type.ebookElectronic books (EPUB, PDF, etc.)
MAGAZINEmagazinebook.type.magazinePeriodical magazines
ARTICLEarticlebook.type.articleIndividual journal/conference articles
NEWSPAPERnewspaperbook.type.newspaperDaily or weekly newspapers
PERIODICALperiodicalbook.type.periodicalGeneric periodicals not covered above
FILMfilmbook.type.filmMovies and film recordings
SOFTWAREsoftwarebook.type.softwareSoftware / digital media
THESISthesisbook.type.thesisAcademic theses and dissertations
MISCmiscbook.type.miscCatch-all for uncategorised entries

Architecture

The enum is used as a property type on the BookDO entity (the domain object for bibliographic entries). Because it implements I18nEnum, the UI layer can call BookType.BOOK.i18nKey to obtain the property key "book.type.book" and look up the localised string (e.g. "Buch" in German, "Book" in English). This keeps display logic out of the enum itself.

The key constructor parameter serves dual purposes: it forms the rightmost segment of the i18n key and can be used as a database-safe stored value (e.g. "ebook" rather than "EBOOK"). The convention of passing a lowercase key to the i18n property path avoids casing issues in different front-end frameworks.

Relationship to I18nEnum

I18nEnum is a ProjectForge interface that requires a single property: val i18nKey: String. Any enum implementing it can be rendered in the UI by looking up the returned key in the application's resource bundles. This pattern avoids hard-coding display strings in enum constants and enables multi-language support without modifying Kotlin source code.

Git History

CommitDescription
868d6abb7Copyright year bump: 2025 → 2026
63081666fSource file headers: 2024 → 2025
4c04cfd65MAJOR: Migration of integer IDs to Long (entity-wide change, touched enums via recompilation)
923f5c64bMigration stuff in progress… (likely part of the ID migration or Kotlin conversion)
b6092df09Copyright 2023 → 2024
ab45d51faCopyright 2001-2022 → 2001-2023
ceb63e8a1Source code header: (C) 2001-2021
7c79f1922Copyright of source header → 2020
dd5ca38acCopyRight of all java file-headers updated or created
9ebb88522Initial commit

Design Rationale

Why an enum instead of a database lookup table?

Book types are a small, stable, closed set. An enum provides compile-time type safety, avoids a join at query time, and eliminates the need for a separate administration UI to manage categories. The trade-off is that adding a new type requires a code change and a redeployment — acceptable for a domain where new media categories are rare.

Why include non-book items like FILM and SOFTWARE?

ProjectForge's book module is really a general bibliographic/media catalogue. The name "book" is a simplification for the user-facing module label; internally, the system tracks a broader range of media. The expanded enum values reflect the actual use cases of the user base (likely an organisation that manages diverse reference materials).

Why I18nEnum instead of storing display names directly?

Hard-coding display strings in Kotlin enums would make multi-language support impossible without duplicating the enum for each locale. The I18nEnum pattern decouples the symbolic constant (EBOOK) from its human-readable label, allowing translators to provide localised values in resource-bundle properties files.