Skip to content

Refactor project file structure - #941

Merged
dennisvang merged 72 commits into
masterfrom
dev/856-project-file-structure
Aug 28, 2026
Merged

Refactor project file structure#941
dennisvang merged 72 commits into
masterfrom
dev/856-project-file-structure

Conversation

@dennisvang

@dennisvang dennisvang commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

The big shuffle

Converted the project file structure from the technology-based "folder-by-type" pattern (a.k.a. "package-by-layer") to a domain-based "folder-by-feature" pattern (a.k.a. "package-by-feature"). This makes the code more coherent, easier to navigate, and follows best-practices (see e.g. spring-boot docs).

This is a very large change in terms of file count and lines of code, but nearly all of the changes are simply due to changed package names and or class names, and corresponding changes in imports.

The test file structure now matches the main file structure, except for the acceptance tests (these require thorough refactoring which will be tackled in a separate PR). This is more consistent and allows direct access to the classes from the corresponding main package, so we don't need to import those in the tests anymore.

fixes #856

todo:

  • Add new data migration to fix modified class paths (_class and ACL.className) in mongo documents in existing deployments (_class is added by Spring Data MongoDB). Based on @Document annotations, the following mongo collections need to be updated:

    collection new _class value
    ACL (external) org.fairdatateam.security.acls.domain.MongoAcl
    apiKey org.fairdatateam.fairdatapoint.security.apikey.ApiKey
    event org.fairdatateam.fairdatapoint.index.event.Event
    indexEntry org.fairdatateam.fairdatapoint.index.entry.IndexEntry
    indexSettings org.fairdatateam.fairdatapoint.index.settings.IndexSettings
    membership org.fairdatateam.fairdatapoint.security.membership.Membership
    metadata org.fairdatateam.fairdatapoint.rdf.metadata.Metadata
    metadataSchema org.fairdatateam.fairdatapoint.rdf.schema.MetadataSchema
    metadataSchemaDraft org.fairdatateam.fairdatapoint.rdf.schema.MetadataSchemaDraft
    rdfMigration (external) org.fairdatateam.rdf.migration.entity.RdfMigration
    resourceDefinition org.fairdatateam.fairdatapoint.resource.ResourceDefinition
    searchSavedQuery org.fairdatateam.fairdatapoint.search.SearchSavedQuery
    settings org.fairdatateam.fairdatapoint.settings.Settings
    user org.fairdatateam.fairdatapoint.user.User
    webhook org.fairdatateam.fairdatapoint.index.webhook.Webhook

    Note that some of these collections are only created after some interaction has taken place, e.g. event only appears if index functionality is enabled and a ping has been received, and the settings collections only appear after the corresponding settings have been changed. Same for membershipPermission and searchSavedQuery. Note that it looks like the webhook collection is never created at all (Can we remove the webhook repository? #969).
    -> (added migration 0021 to apply these changes)

  • Note that we should also consider possible leftover nl.dtls.* package names in the _class fields, because earlier (v1.17.3 and v1.19.1) changes in fdp package names did not include a migration for _class... This has slipped through the cracks, probably because spring data mongodb uses a fallback if the _class value does not resolve. -> This was addressed in migration 0021 by simply overwriting any _class value if it does not match the desired value (this does not depend on the namespace of the original value).

  • Test migration from latest release to this version to see if mongo migrations are still working properly -> Tested manually, starting from v1.16.2 (container), v1.17.3 (source), and from latest v1.22.0 (source). Verified that all _class values and ACL.className were updated properly and that the fdp-client can interact with the fdp. Also verified that both org.fairdatateam and nl.dtls namespaces are updated properly.

except for index-specific settings, which have always been treated separately and were already in the new fairdatapoint.index package
and rename database.rdf.repository.MetadataRepository to  metadata.MetadataRdfRepository
and same for corresponding MetadataRepositoryException
to remove ambiguity with respect to database.mongo.repository.MetadataRepository
and adapt src/main/resources accordingly

rename MigrationRunner to DevelopmentMigrationRunner to be consistent with RdfDevelopmentMigrationRunner

rename MongoConfig to MongoDbMigrationConfig and rename RdfRepositoryMigrationConfig to TripleStoreMigrationConfig, for clarity and consistency
and rename RepositoryProperties classes to RdfRepositoryProperties for clarity
resource loader looks for resources relative to class path, so the file structure in java and resources must match
@dennisvang dennisvang added the dev Related to development, e.g. code style, refactoring, github workflows, etc. label Jul 22, 2026
This reverts commit 55887b3.

because it turns out we cannot easily move the other fixtures into the acceptance test package, so better to keep them both in one place...
- fix fully qualified reference to Metadata class in @PreAuthorize
- use SpEL Type T() to ensure that the existence of the class is checked

https://docs.spring.io/spring-framework/reference/core/expressions/language-ref/types.html
@dennisvang
dennisvang marked this pull request as ready for review August 19, 2026 11:31
… files

migration content should not change, obviously

we need a new migration to update these values to the new package names
because it is not only related to migrations: although it does only define a mongock (migration) bean, it also configures mongodb itself via annotations
@dennisvang

dennisvang commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

For reference, here's the explanation of type mapping using _class, from the spring data mongodb docs:

MongoDB collections can contain documents that represent instances of a variety of types. This feature can be useful if you store a hierarchy of classes or have a class with a property of type Object.In the latter case, the values held inside that property have to be read in correctly when retrieving the object.Thus, we need a mechanism to store type information alongside the actual document.

To achieve that, the MappingMongoConverter uses a MongoTypeMapper abstraction with DefaultMongoTypeMapper as its main implementation.Its default behavior to store the fully qualified classname under _class inside the document. [...]

@dennisvang

dennisvang commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

PR was approved by Luiz out-of-band

@dennisvang dennisvang added the migrations Anything to do with migration in the broadest sense of the word. label Aug 28, 2026
@dennisvang
dennisvang merged commit 08af318 into master Aug 28, 2026
14 checks passed
@dennisvang
dennisvang deleted the dev/856-project-file-structure branch August 28, 2026 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dev Related to development, e.g. code style, refactoring, github workflows, etc. migrations Anything to do with migration in the broadest sense of the word.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor project file structure

1 participant