Skip to content

Attributes system#75

Draft
rensPols wants to merge 46 commits intomainfrom
attributes-system
Draft

Attributes system#75
rensPols wants to merge 46 commits intomainfrom
attributes-system

Conversation

@rensPols
Copy link
Member

@rensPols rensPols commented Oct 10, 2025

Introduces the attribute system with scopes

closes #73

Adds `errorResponse` extension functions to `Message`
for simplified error handling in Vert.x event bus.
This allows sending standardized error responses with
failure codes and messages.
Adds website and store-view creation via event bus.
Replaces old createScope method.
Uses `createScopes.kt` for new functions.
Complexity is medium.
The comment indicates a need for stricter
editScope functions and deprecation of the
global one.
Replaces hardcoded string "scopes" with ScopeJdbcVerticle.CACHE_ADDRESS to improve maintainability and reduce potential errors.
Refactors scope tests to use JsonObject.
The Scope data class is deprecated.
Adds ScopeLevel enum with GLOBAL, WEBSITE, and STORE_VIEW values.
Replaces hardcoded string "ScopeCodec" with the class reference to get delivery options. This ensures type safety and avoids potential errors due to typos or inconsistencies.
Adds the Attributes abstract class to define attribute handling
in exDock. This class serves as the foundation for different
types of attributes, providing methods for getting, setting,
and clearing attribute values, as well as type checking. It
also defines abstract methods for attribute creation, deletion
and clearing all attributes.
@github-project-automation github-project-automation bot moved this to Backlog in exDock Oct 10, 2025
@rensPols rensPols requested a review from Moltensnor October 10, 2025 21:08
@rensPols rensPols self-assigned this Oct 10, 2025
@rensPols rensPols added this to the Initial release milestone Oct 10, 2025
@rensPols rensPols added the initialisation part of the initialisation of the project label Oct 10, 2025
Removes unused imports and adds missing ones.
This improves code readability and ensures necessary
dependencies are available.
Refactors scope handling logic and updates event bus
consumers for scope management.

Updates `getScopes.kt` to use cached scopes and modifies
`ScopeJdbcVerticle.kt` to align with changes in scope
handling and adds create website/storeview and edit/delete scope functionality.
Fixes incorrect variable name in error handling within ScopeJdbcVerticle, changing 'res' to 'err'.
Removes unused editScope function and imports.
Improves deleteScope function's query execution.
This commit introduces in-memory caching for scopes to improve performance.
The changes include:

- Added a `cachedScopes` variable to store scopes in memory.
- Updated `createScopes.kt`, `getScopes.kt`, and `ScopeJdbcVerticle.kt` to utilize and update the cache.
- Refactored `getScopes.kt` to initially load all scopes into the cache.
- Added new file `scopes.kt` to contain cachedScopes variable.
…e getAttributeValue functions

Refactors attribute retrieval logic for efficiency.
Uses cached scopes and Future.all for concurrent data
fetching from different scope levels (global, website,
scope). Fixes scoping and data merging.
…ctions

Refactor `getAttributeValue` to retrieve data by scope,
allowing for global, website, and scope-specific data.
The getScopedData and getScopedDataSingle functions were
changed from private to internal, increasing their visibility
within the module. This allows for greater flexibility and
testability.
The `client` field in the `Attributes` class was changed
from `protected` to `internal`. This restricts access to
only modules within the same package.
The function `getCollectionKey` was changed from private to internal.
This allows it to be accessed from other modules within the project.
The `clearAllAttributesValue` function was made non-abstract and implemented to remove attribute values for a given entity ID from all cached scopes and the main collection. This change ensures that attribute values are properly cleared across the entire system.
Adds `isValidAttributeKey` to validate attribute keys.
Uses regex to enforce naming conventions.
Adds extension function to handle Future failures by failing the provided Promise.
…configuration

The Attributes class was refactored to handle the async attributes configuration.
Specifically includes:

- Renamed getAttributeType function to return a Future to handle asynchronous type checking.
- Moved `checkValueType` to return a Future to support async value validation.
- Modified `setAttributeValue` and `setAttributesValue` to perform asynchronous type checking before setting attributes.
- Added proper Future handling for asynchronous operations.
Adds onSuccess method to complement onFailure for promise completion.
This adds an `onSuccess` extension function to `Future`
that completes a provided `Promise` when the `Future`
completes successfully.
Adds an abstract val allowedTypes property to the Attributes class
Updates checkValueType method to use KClass.
The `checkValueType` methods and `setAttributeValue` and `setAttributesValue` functions were refactored to improve type checking and error handling for attribute values. The changes ensure that the correct type is used for each attribute, and clearer error messages are displayed when type mismatches occur.
This commit refactors the Attributes class to improve
attribute management and add support for creating
attributes. The changes include:

- Add validation for attribute keys
- Improve the logic for retrieving scoped data
- Add support for creating attributes
Adds a `ProductAttributes` class that extends `Attributes`.
This class defines the allowed types for product attributes
and the collection name for products.
Adds function to clear all values for an attribute.
This assists with attribute removal by resetting values.
Adds extension functions to Future to simplify
handling both success and failure cases for promises.
This avoids redundant code.
Adds AttributeConfiguration.kt to define the structure
for attribute configurations including key, name, data
type, and scope level.  Provides a toDocument() function
for converting to a JsonObject.
This commit introduces the concept of system attributes and refactors the ProductAttributes class to include them.

- Adds a `systemAttributes` property to the `Attributes` class.
- Implements the `systemAttributes` in `ProductAttributes` class.
Adds an empty `initialiseSystemAttributes` function to the
`Attributes` class. This function will check for missing
system attributes and add them.
Copy link
Collaborator

@Moltensnor Moltensnor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good, but there a some small things that need some changes. Do make sure that the pipeline passes before merging


internal fun EventBus.getScopeById(client: MongoClient) {
this.consumer<String>("process.scope.getScopeById").handler { message ->
val websiteId = message.body()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This key is supposed to be an ObjectID instead of a String. So in needs to be initialized by ObjectId(data.getString(...))

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also put the scopes in the ExdockCache but we can also do that later. The cache is a bit better optimized for data fetching

@github-project-automation github-project-automation bot moved this from Backlog to denied in exDock Oct 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

initialisation part of the initialisation of the project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement the attributes system

2 participants