Assessment review: The archive feature is a practice proposal, not the individually agreed additional use case in rubric row 11. Resolve required processing and verified defects before claiming assessment readiness. See the rubric matrix.
Use the course to implement and explain one change end to end. The capstone is a proposed extension, not code already present in the pinned backend.
Assessment prerequisites
First reproduce and correct the review findings, then complete and demonstrate the asynchronous processing flow described in the assessment review. Use the rubric to collect Compose, CI, issue-tracking, documentation, and oral-explanation evidence. The archive exercise below is supplementary unless it matches your individually approved use case.
Feature brief: archive a document
An actor with document write access can archive it. Archived documents retain their files and metadata but are omitted from ordinary lists and search unless explicitly requested. Unarchiving follows the same write policy. Existing sharing rules still apply. Choose and document whether downloads remain available to authorized readers.
Build in dependency order
- Write an acceptance matrix for owner-only/shared documents and each role. Include stale version and concurrent sharing changes.
- Add an explicit domain representation of archive state. Decide whether a nullable timestamp or lifecycle type expresses the required rules.
- Extend the authoritative backend OpenAPI contract with request intent and response state. Regenerate API/DTOs.
- Add a forward migration, entity property, and model/entity mapping. Preserve identity and version.
- Update persistence queries so archive filtering and visibility filtering compose correctly.
- Implement service authorization and transitions. Preserve refresh/locking behavior rather than trusting the initial snapshot.
- Keep controller changes limited to HTTP conversion and delegation.
- Update in-memory search candidate selection and result expectations.
- Add tests at the service, mapper/persistence, and HTTP boundaries. Run targeted checks, then the full suite.
Design review prompts
Does this new state belong to the existing document consistency boundary? Can an archive request change ownership or team by accident? Does a default in the DTO make omission indistinguishable from an explicit operation? Does the mapper preserve version? Does the update need any filesystem work at all?
Explain why a new enum value in ProcessingStatus might confuse processing and archival concerns. A separate lifecycle dimension may better express the requirement. Justify your choice from behavior rather than from a desire to reuse an existing enum.
Oral explanation exercise
In five minutes, explain a single request using the terms controller, application service, model, persistence port, adapter, entity mapper, repository, and transaction. Then answer:
- Which part is DDD-inspired, and which parts are pragmatic framework coupling?
- What does the current ACL protect, and what would a remote-service ACL additionally translate?
- What does MapStruct prove at compile time, and what must tests still prove?
- Which Kotlin features reduce boilerplate, and which require care at Java/JPA boundaries?
- How does a concurrent sharing change affect authorization?
- What cannot be made atomic by a database transaction alone?
Verification gate
Deliver the implementation, acceptance matrix, and evidence ledger in your practice project. A reviewer should be able to trace one new field through contract, domain, storage, response, and tests without finding JPA entities in a controller or service. Mark this chapter complete only when you can explain the failure cases as clearly as the happy path.
Read the implementation
Complete source walkthrough
Read these pinned files alongside the explanation above. These are the inspected implementation, not the capstone solution.
DocumentRepository.kt
package at.fhtw.swen3.paperless.document.persistence.repository
import at.fhtw.swen3.paperless.document.entity.DocumentEntity
import java.util.UUID
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.query.Param
interface DocumentRepository : JpaRepository<DocumentEntity, UUID> {
@Query(
value = """
select d from DocumentEntity d
left join d.documentType t
where ((d.team is null and d.owner.id = :ownerId) or d.team.id in :teamIds)
and (:documentTypeId is null or t.id = :documentTypeId)
""",
countQuery = """
select count(d) from DocumentEntity d
left join d.documentType t
where ((d.team is null and d.owner.id = :ownerId) or d.team.id in :teamIds)
and (:documentTypeId is null or t.id = :documentTypeId)
"""
)
fun findVisibleDocuments(
@Param("ownerId") ownerId: UUID,
@Param("teamIds") teamIds: Set<UUID>,
@Param("documentTypeId") documentTypeId: UUID?,
pageable: Pageable
): Page<DocumentEntity>
@Query(
value = """
select d from DocumentEntity d
left join d.documentType t
where d.team is null and d.owner.id = :ownerId
and (:documentTypeId is null or t.id = :documentTypeId)
""",
countQuery = """
select count(d) from DocumentEntity d
left join d.documentType t
where d.team is null and d.owner.id = :ownerId
and (:documentTypeId is null or t.id = :documentTypeId)
"""
)
fun findOwnerOnlyDocuments(
@Param("ownerId") ownerId: UUID,
@Param("documentTypeId") documentTypeId: UUID?,
pageable: Pageable
): Page<DocumentEntity>
@Query(
"""
select d from DocumentEntity d
where (d.team is null and d.owner.id = :ownerId) or d.team.id in :teamIds
"""
)
fun findVisibleDocuments(
@Param("ownerId") ownerId: UUID,
@Param("teamIds") teamIds: Set<UUID>
): List<DocumentEntity>
@Query(
"""
select d from DocumentEntity d
where d.team is null and d.owner.id = :ownerId
"""
)
fun findOwnerOnlyDocuments(@Param("ownerId") ownerId: UUID): List<DocumentEntity>
}
DocumentEntity.kt
package at.fhtw.swen3.paperless.document.entity
import at.fhtw.swen3.paperless.common.entity.AbstractEntity
import at.fhtw.swen3.paperless.document.model.ProcessingStatus
import at.fhtw.swen3.paperless.documenttype.entity.DocumentTypeEntity
import at.fhtw.swen3.paperless.team.entity.TeamEntity
import at.fhtw.swen3.paperless.user.entity.UserEntity
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.EnumType
import jakarta.persistence.Enumerated
import jakarta.persistence.FetchType
import jakarta.persistence.JoinColumn
import jakarta.persistence.ManyToOne
import jakarta.persistence.Table
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.PositiveOrZero
import jakarta.validation.constraints.Size
import java.time.Instant
import java.util.UUID
@Entity
@Table(name = "documents")
class DocumentEntity(
id: UUID? = null,
@field:NotBlank
@field:Size(max = 255)
@Column(nullable = false)
val title: String = "",
@field:NotBlank
@Column(nullable = false)
val originalFilename: String = "",
@field:NotBlank
@Column(nullable = false)
val contentType: String = "",
@field:PositiveOrZero
@Column(nullable = false)
val fileSize: Long = 0,
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "owner_id", nullable = false, updatable = false)
val owner: UserEntity,
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "team_id")
val team: TeamEntity? = null,
@Enumerated(EnumType.STRING)
@Column(nullable = false)
val status: ProcessingStatus = ProcessingStatus.PENDING,
@Column(columnDefinition = "TEXT")
val ocrContent: String? = null,
@Column(columnDefinition = "TEXT")
val summary: String? = null,
val storageKey: String? = null,
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "document_type_id")
val documentType: DocumentTypeEntity? = null,
createdAt: Instant = Instant.now(),
updatedAt: Instant = Instant.now(),
version: Long = 0
) : AbstractEntity(id, createdAt, updatedAt, version)
Document.kt
package at.fhtw.swen3.paperless.document.model
import at.fhtw.swen3.paperless.documenttype.model.DocumentType
import java.time.Instant
import java.util.UUID
data class Document(
val id: UUID?,
val title: String,
val originalFilename: String,
val contentType: String,
val fileSize: Long,
val status: ProcessingStatus,
val ocrContent: String?,
val summary: String?,
val storageKey: String?,
val documentType: DocumentType?,
val createdAt: Instant,
val updatedAt: Instant,
val ownerId: UUID,
val teamId: UUID? = null,
val version: Long = 0
)