-
Notifications
You must be signed in to change notification settings - Fork 274
Condition Matcher for displaying notifications #5093
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
Merged
manodnyab
merged 11 commits into
feature/ideNotifs
from
manodnyb/checkRulesForNotifications
Nov 21, 2024
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c3cc2bf
Display toast notifications with actions
manodnyab 09729c7
Condition matcher for displaying notifications
manodnyab e909a0e
Modified deserialization cases and added tests
manodnyab 5a84e39
Merge branch 'feature/ideNotifs' into manodnyb/checkRulesForNotificat…
manodnyab 56c1888
not required file change
manodnyab a981227
Merge remote-tracking branch 'origin/manodnyb/checkRulesForNotificati…
manodnyab dbfcefc
feedback 1
manodnyab 823ea7f
Merge remote-tracking branch 'origin/feature/ideNotifs' into manodnyb…
manodnyab 218c8ed
modified the base class
manodnyab 5743e94
modified test instance lifecycle
manodnyab 899da9d
Merge branch 'feature/ideNotifs' into manodnyb/checkRulesForNotificat…
manodnyab 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
13 changes: 13 additions & 0 deletions
13
...munity/src/software/aws/toolkits/jetbrains/core/notifications/CustomizeNotificationsUi.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,13 @@ | ||
| // Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package software.aws.toolkits.jetbrains.core.notifications | ||
|
|
||
| fun checkSeverity(notificationSeverity: String): NotificationSeverity = when (notificationSeverity) { | ||
| "Critical" -> NotificationSeverity.CRITICAL | ||
| "Warning" -> NotificationSeverity.WARNING | ||
| "Info" -> NotificationSeverity.INFO | ||
| else -> NotificationSeverity.INFO | ||
| } | ||
|
|
||
| // TODO: Add actions that can be performed from the notifications here | ||
8 changes: 8 additions & 0 deletions
8
...unity/src/software/aws/toolkits/jetbrains/core/notifications/DisplayToastNotifications.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,8 @@ | ||
| // Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package software.aws.toolkits.jetbrains.core.notifications | ||
|
|
||
| import com.intellij.openapi.project.Project | ||
|
||
|
|
||
| object DisplayToastNotifications {} | ||
|
Check notice on line 8 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/notifications/DisplayToastNotifications.kt
|
||
|
||
121 changes: 121 additions & 0 deletions
121
...src/software/aws/toolkits/jetbrains/core/notifications/NotificationCustomDeserializers.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,121 @@ | ||
| // Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package software.aws.toolkits.jetbrains.core.notifications | ||
|
|
||
| import com.fasterxml.jackson.core.JsonParser | ||
| import com.fasterxml.jackson.core.JsonToken | ||
| import com.fasterxml.jackson.databind.DeserializationContext | ||
| import com.fasterxml.jackson.databind.JsonDeserializer | ||
| import com.fasterxml.jackson.databind.JsonMappingException | ||
| import com.fasterxml.jackson.databind.JsonNode | ||
|
|
||
| class OperationConditionDeserializer : JsonDeserializer<NotificationExpression.OperationCondition>() { | ||
| override fun deserialize(parser: JsonParser, ctxt: DeserializationContext): NotificationExpression.OperationCondition = when (parser.currentToken) { | ||
| JsonToken.VALUE_STRING -> { | ||
| // Handle direct string value | ||
| NotificationExpression.OperationCondition(parser.valueAsString) | ||
| } | ||
| else -> throw JsonMappingException(parser, "Cannot deserialize OperatingCondition") | ||
| } | ||
| } | ||
|
|
||
| class ComparisonConditionDeserializer : JsonDeserializer<NotificationExpression.ComparisonCondition>() { | ||
| override fun deserialize(parser: JsonParser, ctxt: DeserializationContext): NotificationExpression.ComparisonCondition { | ||
| val op = OperationConditionDeserializer().deserialize(parser, ctxt) | ||
| return NotificationExpression.ComparisonCondition(op.value) | ||
| } | ||
| } | ||
|
|
||
| class NotEqualsConditionDeserializer : JsonDeserializer<NotificationExpression.NotEqualsCondition>() { | ||
| override fun deserialize(parser: JsonParser, ctxt: DeserializationContext): NotificationExpression.NotEqualsCondition { | ||
| val op = OperationConditionDeserializer().deserialize(parser, ctxt) | ||
| return NotificationExpression.NotEqualsCondition(op.value) | ||
| } | ||
| } | ||
| class GreaterThanConditionDeserializer : JsonDeserializer<NotificationExpression.GreaterThanCondition>() { | ||
| override fun deserialize(parser: JsonParser, ctxt: DeserializationContext): NotificationExpression.GreaterThanCondition { | ||
| val op = OperationConditionDeserializer().deserialize(parser, ctxt) | ||
| return NotificationExpression.GreaterThanCondition(op.value) | ||
| } | ||
| } | ||
| class GreaterThanOrEqualsConditionDeserializer : JsonDeserializer<NotificationExpression.GreaterThanOrEqualsCondition>() { | ||
| override fun deserialize(parser: JsonParser, ctxt: DeserializationContext): NotificationExpression.GreaterThanOrEqualsCondition { | ||
| val op = OperationConditionDeserializer().deserialize(parser, ctxt) | ||
| return NotificationExpression.GreaterThanOrEqualsCondition(op.value) | ||
| } | ||
| } | ||
| class LessThanConditionDeserializer : JsonDeserializer<NotificationExpression.LessThanCondition>() { | ||
| override fun deserialize(parser: JsonParser, ctxt: DeserializationContext): NotificationExpression.LessThanCondition { | ||
| val op = OperationConditionDeserializer().deserialize(parser, ctxt) | ||
| return NotificationExpression.LessThanCondition(op.value) | ||
| } | ||
| } | ||
| class LessThanOrEqualsConditionDeserializer : JsonDeserializer<NotificationExpression.LessThanOrEqualsCondition>() { | ||
| override fun deserialize(parser: JsonParser, ctxt: DeserializationContext): NotificationExpression.LessThanOrEqualsCondition { | ||
| val op = OperationConditionDeserializer().deserialize(parser, ctxt) | ||
| return NotificationExpression.LessThanOrEqualsCondition(op.value) | ||
| } | ||
| } | ||
| class ComplexOperationConditionDeserializer : JsonDeserializer<NotificationExpression.ComplexOperationCondition>() { | ||
| override fun deserialize(parser: JsonParser, ctxt: DeserializationContext): NotificationExpression.ComplexOperationCondition { | ||
| val node = parser.codec.readTree<JsonNode>(parser) | ||
| if (!node.isArray) { | ||
| throw JsonMappingException(parser, "anyOf/noneOf must contain an array of values") | ||
| } | ||
| val values = node.map { it.asText() } | ||
| return NotificationExpression.ComplexOperationCondition(values) | ||
| } | ||
| } | ||
| class AnyOfConditionDeserializer : JsonDeserializer<NotificationExpression.AnyOfCondition>() { | ||
| override fun deserialize(parser: JsonParser, ctxt: DeserializationContext): NotificationExpression.AnyOfCondition { | ||
| val op = ComplexOperationConditionDeserializer().deserialize(parser, ctxt) | ||
| return NotificationExpression.AnyOfCondition(op.value) | ||
| } | ||
| } | ||
|
|
||
| class NoneOfConditionDeserializer : JsonDeserializer<NotificationExpression.NoneOfCondition>() { | ||
| override fun deserialize(parser: JsonParser, ctxt: DeserializationContext): NotificationExpression.NoneOfCondition { | ||
| val op = ComplexOperationConditionDeserializer().deserialize(parser, ctxt) | ||
| return NotificationExpression.NoneOfCondition(op.value) | ||
| } | ||
| } | ||
|
|
||
| class ComplexConditionDeserializer : JsonDeserializer<NotificationExpression.ComplexCondition>() { | ||
| override fun deserialize(parser: JsonParser, ctxt: DeserializationContext): NotificationExpression.ComplexCondition { | ||
| val node = parser.codec.readTree<JsonNode>(parser) | ||
| if (!node.isArray) { | ||
| throw JsonMappingException(parser, "or/and must contain an array of values") | ||
| } | ||
| return NotificationExpression.ComplexCondition(node.toNotificationExpressions(parser)) | ||
| } | ||
| } | ||
| class OrConditionDeserializer : JsonDeserializer<NotificationExpression.OrCondition>() { | ||
| override fun deserialize(parser: JsonParser, ctxt: DeserializationContext): NotificationExpression.OrCondition { | ||
| val op = ComplexConditionDeserializer().deserialize(parser, ctxt) | ||
| return NotificationExpression.OrCondition(op.expectedValueList) | ||
| } | ||
| } | ||
|
|
||
| class AndConditionDeserializer : JsonDeserializer<NotificationExpression.AndCondition>() { | ||
| override fun deserialize(parser: JsonParser, ctxt: DeserializationContext): NotificationExpression.AndCondition { | ||
| val op = ComplexConditionDeserializer().deserialize(parser, ctxt) | ||
| return NotificationExpression.AndCondition(op.expectedValueList) | ||
| } | ||
| } | ||
|
|
||
| class NotConditionDeserializer : JsonDeserializer<NotificationExpression.NotCondition>() { | ||
| override fun deserialize(p: JsonParser, ctxt: DeserializationContext): NotificationExpression.NotCondition { | ||
| val node = p.codec.readTree<JsonNode>(p) | ||
| val parser = node.traverse(p.codec) | ||
| parser.nextToken() | ||
|
|
||
| return NotificationExpression.NotCondition(parser.readValueAs(NotificationExpression::class.java)) | ||
| } | ||
| } | ||
|
|
||
| private fun JsonNode.toNotificationExpressions(p: JsonParser): List<NotificationExpression> = this.map { element -> | ||
| val parser = element.traverse(p.codec) | ||
| parser.nextToken() | ||
| parser.readValueAs(NotificationExpression::class.java) | ||
| } |
183 changes: 183 additions & 0 deletions
183
...mmunity/src/software/aws/toolkits/jetbrains/core/notifications/NotificationFormatUtils.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,183 @@ | ||
| // Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package software.aws.toolkits.jetbrains.core.notifications | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty | ||
| import com.fasterxml.jackson.annotation.JsonSubTypes | ||
| import com.fasterxml.jackson.annotation.JsonTypeInfo | ||
| import com.fasterxml.jackson.databind.annotation.JsonDeserialize | ||
|
|
||
| data class NotificationsList( | ||
| val schema: Schema, | ||
| val notifications: List<NotificationData>?, | ||
| ) | ||
|
|
||
| data class Schema( | ||
| val version: String, | ||
| ) | ||
|
|
||
| data class NotificationData( | ||
| val id: String, | ||
| val schedule: NotificationSchedule, | ||
| val severity: String, | ||
| val condition: NotificationDisplayCondition?, | ||
| val content: NotificationContentDescriptionLocale, | ||
| val actions: List<NotificationFollowupActions>? = emptyList(), | ||
| ) | ||
|
|
||
| data class NotificationSchedule( | ||
| val type: String, | ||
| ) | ||
|
|
||
| enum class NotificationSeverity { | ||
| INFO, | ||
| WARNING, | ||
| CRITICAL, | ||
| } | ||
|
|
||
| data class NotificationContentDescriptionLocale( | ||
| @JsonProperty("en-US") | ||
| val locale: NotificationContentDescription, | ||
| ) | ||
|
|
||
| data class NotificationContentDescription( | ||
| val title: String, | ||
| val description: String, | ||
| ) | ||
|
|
||
| data class NotificationFollowupActions( | ||
| val type: String, | ||
| val content: NotificationFollowupActionsContent, | ||
| ) | ||
|
|
||
| data class NotificationFollowupActionsContent( | ||
| @JsonProperty("en-US") | ||
| val locale: NotificationActionDescription, | ||
| ) | ||
|
|
||
| data class NotificationActionDescription( | ||
| val title: String, | ||
| val url: String?, | ||
| ) | ||
|
|
||
| data class NotificationDisplayCondition( | ||
| val compute: ComputeType?, | ||
| val os: SystemType?, | ||
| val ide: SystemType?, | ||
| val extension: List<ExtensionType>?, | ||
| val authx: List<AuthxType>?, | ||
| ) | ||
|
|
||
| data class ComputeType( | ||
| val type: NotificationExpression?, | ||
| val architecture: NotificationExpression?, | ||
| ) | ||
|
|
||
| data class SystemType( | ||
| val type: NotificationExpression?, | ||
| val version: NotificationExpression?, | ||
| ) | ||
|
|
||
| data class ExtensionType( | ||
| val id: String?, | ||
| val version: NotificationExpression?, | ||
| ) | ||
|
|
||
| @JsonTypeInfo( | ||
| use = JsonTypeInfo.Id.NAME, | ||
| include = JsonTypeInfo.As.WRAPPER_OBJECT | ||
| ) | ||
| @JsonSubTypes( | ||
| JsonSubTypes.Type(value = NotificationExpression.ComparisonCondition::class, name = "=="), | ||
| JsonSubTypes.Type(value = NotificationExpression.NotEqualsCondition::class, name = "!="), | ||
| JsonSubTypes.Type(value = NotificationExpression.GreaterThanCondition::class, name = ">"), | ||
| JsonSubTypes.Type(value = NotificationExpression.GreaterThanOrEqualsCondition::class, name = ">="), | ||
| JsonSubTypes.Type(value = NotificationExpression.LessThanCondition::class, name = "<"), | ||
| JsonSubTypes.Type(value = NotificationExpression.LessThanOrEqualsCondition::class, name = "<="), | ||
| JsonSubTypes.Type(value = NotificationExpression.AnyOfCondition::class, name = "anyOf"), | ||
| JsonSubTypes.Type(value = NotificationExpression.NotCondition::class, name = "not"), | ||
| JsonSubTypes.Type(value = NotificationExpression.OrCondition::class, name = "or"), | ||
| JsonSubTypes.Type(value = NotificationExpression.AndCondition::class, name = "and"), | ||
| JsonSubTypes.Type(value = NotificationExpression.NoneOfCondition::class, name = "noneOf") | ||
| ) | ||
| sealed interface NotificationExpression { | ||
| @JsonDeserialize(using = NotConditionDeserializer::class) | ||
| data class NotCondition( | ||
| val expectedValue: NotificationExpression, | ||
| ) : NotificationExpression | ||
|
|
||
| @JsonDeserialize(using = OrConditionDeserializer::class) | ||
| data class OrCondition( | ||
| val expectedValueList: List<NotificationExpression>, | ||
| ) : NotificationExpression | ||
|
|
||
| @JsonDeserialize(using = AndConditionDeserializer::class) | ||
| data class AndCondition( | ||
| val expectedValueList: List<NotificationExpression>, | ||
| ) : NotificationExpression | ||
|
|
||
| @JsonDeserialize(using = ComplexConditionDeserializer::class) | ||
| data class ComplexCondition( | ||
| val expectedValueList: List<NotificationExpression>, | ||
| ) : NotificationExpression | ||
|
|
||
| // General class for comparison operators | ||
| @JsonDeserialize(using = OperationConditionDeserializer::class) | ||
| data class OperationCondition( | ||
| val value: String, | ||
| ) : NotificationExpression | ||
|
|
||
| @JsonDeserialize(using = ComplexOperationConditionDeserializer::class) | ||
| data class ComplexOperationCondition( | ||
| val value: List<String>, | ||
| ) : NotificationExpression | ||
|
|
||
| @JsonDeserialize(using = ComparisonConditionDeserializer::class) | ||
| data class ComparisonCondition( | ||
| val value: String, | ||
| ) : NotificationExpression | ||
|
|
||
| @JsonDeserialize(using = NotEqualsConditionDeserializer::class) | ||
| data class NotEqualsCondition( | ||
| val value: String, | ||
| ) : NotificationExpression | ||
|
|
||
| @JsonDeserialize(using = GreaterThanConditionDeserializer::class) | ||
| data class GreaterThanCondition( | ||
| val value: String, | ||
| ) : NotificationExpression | ||
|
|
||
| @JsonDeserialize(using = GreaterThanOrEqualsConditionDeserializer::class) | ||
| data class GreaterThanOrEqualsCondition( | ||
| val value: String, | ||
| ) : NotificationExpression | ||
|
|
||
| @JsonDeserialize(using = LessThanConditionDeserializer::class) | ||
| data class LessThanCondition( | ||
| val value: String, | ||
| ) : NotificationExpression | ||
|
|
||
| @JsonDeserialize(using = LessThanOrEqualsConditionDeserializer::class) | ||
| data class LessThanOrEqualsCondition( | ||
| val value: String, | ||
| ) : NotificationExpression | ||
|
|
||
| @JsonDeserialize(using = AnyOfConditionDeserializer::class) | ||
| data class AnyOfCondition( | ||
| val value: List<String>, | ||
| ) : NotificationExpression | ||
|
|
||
| @JsonDeserialize(using = NoneOfConditionDeserializer::class) | ||
| data class NoneOfCondition( | ||
| val value: List<String>, | ||
| ) : NotificationExpression | ||
| } | ||
|
|
||
| data class AuthxType( | ||
| val feature: String, | ||
| val type: NotificationExpression?, | ||
| val region: NotificationExpression?, | ||
| val connectionState: NotificationExpression?, | ||
| val ssoScopes: NotificationExpression?, | ||
| ) |
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
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.
Check warning
Code scanning / QDJVMC
Unused symbol Warning