Skip to content
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

Allow event metrics to have several actions to accomodate tagging during creation/update #5106

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class BlazegraphViewsSerializationSuite extends SerializationSuite {
instant,
subject,
event.rev,
action,
Set(action),
projectRef,
Label.unsafe("myorg"),
event.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ class CompositeViewsSerializationSuite extends SerializationSuite with Composite
Instant.EPOCH,
subject,
event.rev,
event match {
case _: CompositeViewCreated => Created
case _: CompositeViewUpdated => Updated
case _: CompositeViewTagAdded => Tagged
case _: CompositeViewDeprecated => Deprecated
case _: CompositeViewUndeprecated => Undeprecated
},
Set(
event match {
case _: CompositeViewCreated => Created
case _: CompositeViewUpdated => Updated
case _: CompositeViewTagAdded => Tagged
case _: CompositeViewDeprecated => Deprecated
case _: CompositeViewUndeprecated => Undeprecated
}
),
projectRef,
Label.unsafe("myorg"),
event.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object MetricsStream {
Instant.EPOCH,
Anonymous,
1,
Created,
Set(Created),
projectRef1,
org,
iri"http://bbp.epfl.ch/file1",
Expand All @@ -40,7 +40,7 @@ object MetricsStream {
Instant.EPOCH,
Anonymous,
2,
Updated,
Set(Updated),
projectRef1,
org,
iri"http://bbp.epfl.ch/file1",
Expand All @@ -55,7 +55,7 @@ object MetricsStream {
Instant.EPOCH,
Anonymous,
3,
Tagged,
Set(Tagged),
projectRef1,
org,
iri"http://bbp.epfl.ch/file1",
Expand All @@ -68,7 +68,7 @@ object MetricsStream {
Instant.EPOCH,
Anonymous,
4,
TagDeleted,
Set(TagDeleted),
projectRef1,
org,
iri"http://bbp.epfl.ch/file1",
Expand All @@ -81,7 +81,7 @@ object MetricsStream {
Instant.EPOCH,
Anonymous,
1,
Created,
Set(Created),
projectRef2,
org,
iri"http://bbp.epfl.ch/file2",
Expand All @@ -96,7 +96,7 @@ object MetricsStream {
Instant.EPOCH,
Anonymous,
2,
Deprecated,
Set(Deprecated),
projectRef2,
org,
iri"http://bbp.epfl.ch/file2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class ElasticSearchViewSerializationSuite extends SerializationSuite {
instant,
subject,
event.rev,
action,
Set(action),
projectRef,
Label.unsafe("myorg"),
event.id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ch.epfl.bluebrain.nexus.delta.plugins.storage.files.model

import cats.syntax.all._
import akka.http.scaladsl.model.ContentType
import ch.epfl.bluebrain.nexus.delta.kernel.utils.FileUtils
import ch.epfl.bluebrain.nexus.delta.plugins.storage.files.model.FileAttributes.FileAttributesOrigin
Expand Down Expand Up @@ -384,15 +385,15 @@ object FileEvent {
ProjectScopedMetric.from(
event,
event match {
case _: FileCreated => Created
case _: FileUpdated => Updated
case _: FileAttributesUpdated => Updated
case _: FileCustomMetadataUpdated => Updated
case _: FileTagAdded => Tagged
case _: FileTagDeleted => TagDeleted
case _: FileDeprecated => Deprecated
case _: FileUndeprecated => Undeprecated
case _: FileCancelledEvent => Cancelled
case c: FileCreated => Set(Created) ++ c.tag.as(Tagged)
case u: FileUpdated => Set(Updated) ++ u.tag.as(Tagged)
case _: FileAttributesUpdated => Set(Updated)
case _: FileCustomMetadataUpdated => Set(Updated)
case _: FileTagAdded => Set(Tagged)
case _: FileTagDeleted => Set(TagDeleted)
case _: FileDeprecated => Set(Deprecated)
case _: FileUndeprecated => Set(Undeprecated)
case _: FileCancelledEvent => Set(Cancelled)
},
event.id,
Set(nxvFile),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,77 +102,77 @@ class FileSerializationSuite extends SerializationSuite with StorageFixtures {
"FileCreated",
created,
loadEvents("files", "file-created.json"),
Created,
Set(Created),
expectedExtraFields(created, Some(1), None, None, None, clientOrigin)
),
(
"FileCreated with metadata",
createdWithMetadata,
loadEvents("files", "file-created-with-metadata.json"),
Created,
Set(Created),
expectedExtraFields(created, Some(1), None, None, None, clientOrigin)
),
(
"FileCreated with tags",
createdTagged,
loadEvents("files", "file-created-tagged.json"),
Created,
Set(Created, Tagged),
expectedExtraFields(createdTagged, Some(1), None, None, None, clientOrigin)
),
(
"FileCreated with tags and keywords",
createdTaggedWithMetadata,
loadEvents("files", "file-created-tagged-with-metadata.json"),
Created,
Set(Created, Tagged),
expectedExtraFields(createdTaggedWithMetadata, Some(1), None, None, None, clientOrigin)
),
(
"FileUpdated",
updated,
loadEvents("files", "file-updated.json"),
Updated,
Set(Updated, Tagged),
expectedExtraFields(updated, Some(1), Some(12), textContent, Some("txt"), clientOrigin)
),
(
"FileAttributesUpdated",
updatedAttr,
loadEvents("files", "file-attributes-created-updated.json"),
Updated,
Set(Updated),
expectedExtraFields(updatedAttr, None, Some(12), textContent, None, storageOrigin)
),
(
"FileCustomMetadataUpdated",
updatedMetadata,
loadEvents("files", "file-custom-metadata-updated.json"),
Updated,
Set(Updated),
expectedExtraFields(updatedMetadata, None, None, None, None, None)
),
(
"FileTagAdded",
tagged,
loadEvents("files", "file-tag-added.json"),
Tagged,
Set(Tagged),
expectedExtraFields(tagged, None, None, None, None, None)
),
(
"FileTagDeleted",
tagDeleted,
loadEvents("files", "file-tag-deleted.json"),
TagDeleted,
Set(TagDeleted),
expectedExtraFields(tagDeleted, None, None, None, None, None)
),
(
"FileDeprecated",
deprecated,
loadEvents("files", "file-deprecated.json"),
Deprecated,
Set(Deprecated),
expectedExtraFields(deprecated, None, None, None, None, None)
),
(
"FileUndeprecated",
undeprecated,
loadEvents("files", "file-undeprecated.json"),
Undeprecated,
Set(Undeprecated),
expectedExtraFields(undeprecated, None, None, None, None, None)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class StorageSerializationSuite extends SerializationSuite with StorageFixtures
instant,
subject,
event.rev,
action,
Set(action),
projectRef,
Label.unsafe("myorg"),
event.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ sealed trait EventMetric extends Product with Serializable {
* @return
* the action performed
*/
def action: Label
def action: Set[Label]

/**
* @return
Expand Down Expand Up @@ -76,6 +76,7 @@ object EventMetric {
val Deprecated: Label = Label.unsafe("Deprecated")
val Undeprecated: Label = Label.unsafe("Undeprecated")
val Cancelled: Label = Label.unsafe("Cancelled")
val Deleted: Label = Label.unsafe("Deleted")

/**
* Metric extracted from an event independent from an org/project
Expand All @@ -84,7 +85,7 @@ object EventMetric {
instant: Instant,
subject: Subject,
rev: Int,
action: Label,
action: Set[Label],
resourceId: Iri,
types: Set[Iri],
additionalFields: JsonObject
Expand All @@ -99,7 +100,7 @@ object EventMetric {
instant: Instant,
subject: Subject,
rev: Int,
action: Label,
action: Set[Label],
organization: Label,
resourceId: Iri,
types: Set[Iri],
Expand All @@ -115,7 +116,7 @@ object EventMetric {
instant: Instant,
subject: Subject,
rev: Int,
action: Label,
action: Set[Label],
project: ProjectRef,
organization: Label,
resourceId: Iri,
Expand All @@ -128,7 +129,7 @@ object EventMetric {
object ProjectScopedMetric {
def from[E <: ScopedEvent](
event: E,
action: Label,
action: Set[Label],
id: Iri,
types: Set[Iri],
additionalFields: JsonObject
Expand All @@ -144,6 +145,25 @@ object EventMetric {
types,
additionalFields
)

def from[E <: ScopedEvent](
event: E,
action: Label,
id: Iri,
types: Set[Iri],
additionalFields: JsonObject
): ProjectScopedMetric =
ProjectScopedMetric(
event.instant,
event.subject,
event.rev,
Set(action),
event.project,
event.project.organization,
id,
types,
additionalFields
)
}

implicit val eventMetricEncoder: Encoder.AsObject[EventMetric] = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ch.epfl.bluebrain.nexus.delta.sdk.resources.model

import cats.syntax.all._
import ch.epfl.bluebrain.nexus.delta.rdf.IriOrBNode.Iri
import ch.epfl.bluebrain.nexus.delta.rdf.Vocabulary.{contexts, nxv}
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.ContextValue
Expand Down Expand Up @@ -437,14 +438,14 @@ object ResourceEvent {
ProjectScopedMetric.from(
event,
event match {
case _: ResourceCreated => Created
case _: ResourceUpdated => Updated
case _: ResourceRefreshed => Refreshed
case _: ResourceTagAdded => Tagged
case _: ResourceTagDeleted => TagDeleted
case _: ResourceDeprecated => Deprecated
case _: ResourceUndeprecated => Undeprecated
case _: ResourceSchemaUpdated => Updated
case c: ResourceCreated => Set(Created) ++ c.tag.as(Tagged)
case u: ResourceUpdated => Set(Updated) ++ u.tag.as(Tagged)
case _: ResourceRefreshed => Set(Refreshed)
case _: ResourceTagAdded => Set(Tagged)
case _: ResourceTagDeleted => Set(TagDeleted)
case _: ResourceDeprecated => Set(Deprecated)
case _: ResourceUndeprecated => Set(Undeprecated)
case su: ResourceSchemaUpdated => Set(Updated) ++ su.tag.as(Tagged)
},
event.id,
event.types,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class EventMetricSpec extends BaseSpec with CirceLiteral {
Instant.EPOCH,
Anonymous,
2,
EventMetric.Created,
Set(EventMetric.Created),
event.project,
event.project.organization,
id,
Expand All @@ -54,7 +54,7 @@ class EventMetricSpec extends BaseSpec with CirceLiteral {
"subject" : {
"@type" : "Anonymous"
},
"action" : "Created",
"action" : ["Created"],
"@id" : "https://bluebrain.github.io/nexus/vocabulary/id",
"@type" : [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class ProjectSerializationSuite extends SerializationSuite {
instant,
subject,
rev,
action,
Set(action),
ProjectRef(org, proj),
org,
iri"http://localhost/v1/projects/myorg/myproj",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class ResolverSerializationSuite extends SerializationSuite {
instant,
subject,
event.rev,
action,
Set(action),
ProjectRef(org, proj),
org,
event.id,
Expand Down
Loading