-
Notifications
You must be signed in to change notification settings - Fork 0
Attributes system #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
rensPols
wants to merge
46
commits into
main
Choose a base branch
from
attributes-system
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
37b2629
refactor: Moved the getScope eventbus functions to their own file
rensPols 2345060
feat(core): Add error response helper
rensPols 0ccccd1
feat(scope): Add scope creation endpoints
rensPols dfed455
refactor(database): Add TODOs for editScope
rensPols 2b6317b
refactor(scope): Use constant for cache address
rensPols 086c692
Refactor(scope): Refactor scope tests
rensPols 64ca1b3
feat(core): Add ScopeLevel enum
rensPols f6a035a
Convert "scopeKey" to "_id"
rensPols f15547f
fix(core): Use Scope::class for delivery options
rensPols 7b7dfd7
feat(core): Add Attributes abstract class
rensPols 9a3756c
Merge branch 'refs/heads/main' into attributes-system
rensPols 900e0ae
refactor(scope): Simplify imports in ScopeJdbcVerticle
rensPols 486c303
refactor(scope): Refactor scope handling
rensPols f4f42ce
fix(core): Correctly handle error messages
rensPols b5b1dc3
refactor(scope): Simplify ScopeJdbcVerticle
rensPols 63dd983
feat(core): Implement in-memory scope caching
rensPols d17cf16
feat(attributes): Create getScopedDataSingle() function for use in th…
rensPols cf89938
Feat(attributes): Added getScopedData for use in the getAttribute fun…
rensPols 95155bc
refactor(attributes): Make getScopedData functions internal
rensPols 3c77c9d
refactor(attributes): Change client visibility to internal
rensPols 2a932a2
refactor(attributes): Replace cliend.find(One)() with getScopedData(S…
rensPols a892ec4
refactor(core): Make getCollectionKey internal
rensPols 63a640f
fix(core): Make clearAllAttributesValue non-abstract
rensPols 57b48ab
feat(core): Add attribute key validation
rensPols c93a213
feat(core): Add Future.onFailure(promise) extension function
rensPols 05a2b61
refactor(core): Refactor Attributes class to use an async attributes …
rensPols d020bb4
feat(futures): Add Future.onSuccess(promise) extension function
rensPols e1befc7
feat(core): Add onSuccess extension function for Promise<Unit>
rensPols 7990ca9
Fix(core): Add abstract val allowedTypes to Attributes.kt
rensPols 7828c94
refactor(core): Improve attribute type checking
rensPols ed3f814
refactor(attributes): Refactor attribute value checks
rensPols e700a53
Refactor(attributes): Improve attribute management
rensPols c78f562
feat(attributes): Add ProductAttributes class
rensPols 2b91bdd
Grammar correction
rensPols 1f3b6ee
feat(attributes): Add clearAttributeAllValues() to Attributes.kt
rensPols 351ac5d
feat(futures): Add Future.onComplete extension functions
rensPols 3dce3e6
feat(attributes): implement deleteAttribute in Attributes.kt
rensPols eabd912
Improved naming for the attributes config keys
rensPols f8dffef
feat(attributes): Add AttributeConfiguration data class
rensPols 9ab4c74
Refactor(attributes): Implement system attributes
rensPols 028bcb3
feat(attributes): Add initialiseSystemAttributes function
rensPols b863dfc
Resolve JVM name conflict for future parent-promise handlers
rensPols 31f4769
Make sure that "process.scope.create.website" will always return the id
rensPols 5c679f7
Cleaned up "process.scope.deleteScope"
rensPols 760ead4
Fix ScopeJdbcVerticleTest.kt
rensPols b10d9b7
Use the ObjectId class for creating a scope
rensPols File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 16 additions & 117 deletions
133
src/main/kotlin/com/ex_dock/ex_dock/database/scope/ScopeJdbcVerticle.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/main/kotlin/com/ex_dock/ex_dock/database/scope/createScopes.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| package com.ex_dock.ex_dock.database.scope | ||
|
|
||
| import com.ex_dock.ex_dock.global.cachedScopes | ||
| import com.ex_dock.ex_dock.helper.messages.errorResponse | ||
| import io.vertx.core.eventbus.EventBus | ||
| import io.vertx.core.json.JsonObject | ||
| import io.vertx.ext.mongo.MongoClient | ||
| import org.bson.types.ObjectId | ||
|
|
||
| internal fun EventBus.createWebsite(client: MongoClient) { | ||
| this.localConsumer<JsonObject>("process.scope.create.website").handler { message -> | ||
| val data = message.body() | ||
|
|
||
| val keyString = data.getString("scopeKey") ?: return@handler message.fail(400, "The key of the website (scope) is required.") | ||
| val key = ObjectId(keyString) | ||
| val name = | ||
| data.getString("scopeName") ?: return@handler message.fail(400, "The name of the website (scope) is required.") | ||
|
|
||
| client.findOne( | ||
| ScopeJdbcVerticle.CACHE_ADDRESS, | ||
| JsonObject().put("_id", key), | ||
| JsonObject().put("_id", 1), | ||
| ).onFailure { err -> | ||
| message.errorResponse(400, err) | ||
| }.onSuccess { res -> | ||
| if (res != null) return@onSuccess message.fail( | ||
| 409, | ||
| "This function is for creating websites (scope), not editing them." | ||
| ) | ||
|
|
||
| val document = JsonObject().put("_id", key).put("scopeName", name).put("scopeType", "website") | ||
|
|
||
| client.insert(ScopeJdbcVerticle.CACHE_ADDRESS, document).onFailure { err -> | ||
| message.errorResponse(err) | ||
| }.onSuccess { res -> | ||
| cachedScopes.put(keyString, document) | ||
| message.reply(res ?: key) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| internal fun EventBus.createStoreView(client: MongoClient) { | ||
| this.localConsumer<JsonObject>("process.scope.create.store-view").handler { message -> | ||
| val data = message.body() | ||
|
|
||
| val name = | ||
| data.getString("name") ?: return@handler message.fail(400, "The name of the store-view (scope) is required.") | ||
| val keyString = data.getString("key") ?: return@handler message.fail(400, "The key of the store-view (scope) is required.") | ||
| val key = ObjectId(keyString) | ||
| val websiteId = data.getString("websiteId") ?: return@handler message.fail( | ||
| 400, | ||
| "The websiteId of the parent website (scope) is required." | ||
| ) | ||
|
|
||
| client.findOne( | ||
| ScopeJdbcVerticle.CACHE_ADDRESS, | ||
| JsonObject().put("_id", key), | ||
| JsonObject().put("_id", 1), | ||
| ).onFailure { err -> | ||
| message.errorResponse(400, err) | ||
| }.onSuccess { res -> | ||
| if (res != null) return@onSuccess message.fail( | ||
| 409, | ||
| "This function is for creating store-views (scope), not editing them." | ||
| ) | ||
|
|
||
| val searchWebsiteQuery = JsonObject().put("scopeType", "website").put("_id", websiteId) | ||
| client.find(ScopeJdbcVerticle.CACHE_ADDRESS, searchWebsiteQuery).onFailure { err -> | ||
| message.errorResponse(err) | ||
| }.onSuccess { res -> | ||
| if (res.isEmpty()) return@onSuccess message.fail( | ||
| 400, | ||
| "The websiteId of the parent website (scope) does not exist" | ||
| ) | ||
|
|
||
| client.find(ScopeJdbcVerticle.CACHE_ADDRESS, JsonObject().put("_id", key)).onFailure { err -> | ||
| message.errorResponse(err) | ||
| }.onSuccess { res -> | ||
| if (res.isNotEmpty()) return@onSuccess message.fail( | ||
| 400, | ||
| "The key of the store-view (scope) already exists for a scope" | ||
| ) | ||
|
|
||
| val document = JsonObject().put("_id", key).put("scopeName", name).put("scopeType", "store-view") | ||
| .put("websiteId", websiteId) | ||
|
|
||
| client.insert(ScopeJdbcVerticle.CACHE_ADDRESS, document).onFailure { err -> | ||
| message.errorResponse(err) | ||
| }.onSuccess { res -> | ||
| cachedScopes.put(keyString, document) | ||
| message.reply(res ?: key) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
45 changes: 45 additions & 0 deletions
45
src/main/kotlin/com/ex_dock/ex_dock/database/scope/getScopes.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package com.ex_dock.ex_dock.database.scope | ||
|
|
||
| import com.ex_dock.ex_dock.global.cachedScopes | ||
| import com.ex_dock.ex_dock.helper.replyListMessage | ||
| import com.ex_dock.ex_dock.helper.replySingleMessage | ||
| import io.vertx.core.eventbus.EventBus | ||
| import io.vertx.core.json.JsonObject | ||
| import io.vertx.ext.mongo.MongoClient | ||
|
|
||
|
|
||
| internal fun EventBus.getAllScopes(client: MongoClient) { | ||
| this.consumer<String>("process.scope.getAllScopes").handler { message -> | ||
| val query = JsonObject() | ||
|
|
||
| client.find("scopes", query).onSuccess { res -> | ||
| val newCachedScopes = JsonObject() | ||
| for (scope in res) newCachedScopes.put(scope.getString("_id"), scope) | ||
| cachedScopes = newCachedScopes | ||
| }.replyListMessage(message) | ||
| } | ||
| } | ||
|
|
||
| internal fun EventBus.getScopeById(client: MongoClient) { | ||
| this.consumer<String>("process.scope.getScopeById").handler { message -> | ||
| val websiteId = message.body() | ||
| val query = JsonObject() | ||
| .put("_id", websiteId) | ||
|
|
||
| client.find("scopes", query).onSuccess { res -> | ||
| cachedScopes.put(websiteId, res.first()) | ||
| }.replySingleMessage(message) | ||
| } | ||
| } | ||
|
|
||
| internal fun EventBus.getScopesByWebsiteId(client: MongoClient) { | ||
| this.consumer<String>("process.scope.getScopesByWebsiteId").handler { message -> | ||
| val websiteName = message.body() | ||
| val query = JsonObject() | ||
| .put("websiteId", websiteName) | ||
|
|
||
| client.find("scopes", query).onSuccess { res -> | ||
| for (scope in res) cachedScopes.put(scope.getString("_id"), scope) | ||
| }.replyListMessage(message) | ||
| } | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package com.ex_dock.ex_dock.global | ||
|
|
||
| import io.vertx.core.json.JsonObject | ||
|
|
||
| var cachedScopes: JsonObject = JsonObject() |
19 changes: 19 additions & 0 deletions
19
src/main/kotlin/com/ex_dock/ex_dock/helper/attributes/AttributeConfiguration.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package com.ex_dock.ex_dock.helper.attributes | ||
|
|
||
| import com.ex_dock.ex_dock.helper.scopes.ScopeLevel | ||
| import io.vertx.core.json.JsonObject | ||
|
|
||
| data class AttributeConfiguration( | ||
| val attributeKey: String, | ||
| val attributeName: String, | ||
| val attributeDataType: String, | ||
| val scopeLevel: ScopeLevel, | ||
| ) { | ||
| fun toDocument(): JsonObject { | ||
| return JsonObject() | ||
| .put("_id", attributeKey) | ||
| .put("attributeName", attributeName) | ||
| .put("attributeType", attributeDataType) | ||
| .put("attributeScopeLevel", scopeLevel.name) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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(...))