From 9d4ea6047deb44be1ebd4a1181a068335a57b01e Mon Sep 17 00:00:00 2001 From: Kacper Magdziarz <95610011+kmagdziarz@users.noreply.github.com> Date: Wed, 27 Nov 2024 16:18:08 +0100 Subject: [PATCH] [ACS-9040] Project refactoring * Update README.md, add contributing guide * Update dependencies, switch to Junit Jupiter * Cleanup POM * Add dependabot * Add Spotless * Update gitignore --- .github/dependabot.yml | 21 + .github/workflows/ci.yml | 2 +- .gitignore | 10 + README.md | 121 +++-- pom.xml | 315 +++++++----- .../alfresco/repo/event/EventAttributes.java | 14 +- .../repo/event/databind/DateSerializer.java | 10 +- .../event/databind/DateTimeDeserializer.java | 2 +- .../event/databind/DateTimeSerializer.java | 2 +- .../event/databind/ExtensionDeserializer.java | 33 +- .../event/databind/ExtensionSerializer.java | 8 +- .../event/databind/ObjectMapperFactory.java | 19 +- .../event/databind/ResourceDeserializer.java | 23 +- .../event/extension/ExtensionAttributes.java | 18 +- .../extension/ExtensionAttributesImpl.java | 6 +- .../repo/event/util/NodeResourceUtils.java | 61 +-- .../event/v1/model/AbstractNodeResource.java | 2 +- .../repo/event/v1/model/ChildAssocInfo.java | 3 +- .../v1/model/ChildAssociationResource.java | 10 +- .../repo/event/v1/model/ContentInfo.java | 17 +- .../repo/event/v1/model/EventData.java | 6 +- .../repo/event/v1/model/EventType.java | 23 +- .../repo/event/v1/model/NodeResource.java | 133 +++-- .../repo/event/v1/model/PeerAssocInfo.java | 3 +- .../v1/model/PeerAssociationResource.java | 6 +- .../repo/event/v1/model/RepoEvent.java | 52 +- .../repo/event/v1/model/Resource.java | 3 +- .../repo/event/v1/model/UserInfo.java | 9 +- .../event/util/NodeResourceUtilsTest.java | 108 ++-- .../alfresco/repo/event/util/TestUtil.java | 49 +- .../repo/event/v1/model/EventTest.java | 473 +++++++++--------- .../repo/event/v1/model/NodeResourceTest.java | 13 +- .../model/extension/EventExtensionTest.java | 155 +++--- .../schema/ChildAssociationResource.java | 9 +- .../schema/EventDataWithResourceBefore.java | 7 +- .../EventDataWithoutResourceBefore.java | 9 +- .../event/v1/model/schema/NodeResource.java | 33 +- .../model/schema/PeerAssociationResource.java | 9 +- .../repo/event/v1/model/schema/RepoEvent.java | 18 +- .../repo/event/v1/model/schema/Required.java | 4 +- .../generator/JsonSchemaGeneratorTest.java | 50 +- 41 files changed, 981 insertions(+), 888 deletions(-) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..ebcc078 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,21 @@ +version: 2 +registries: + maven-alfresco-internal: + type: maven-repository + url: https://artifacts.alfresco.com/nexus/content/groups/internal + username: ${{secrets.NEXUS_USERNAME}} + password: ${{secrets.NEXUS_PASSWORD}} +updates: + - package-ecosystem: "maven" + directory: "/" + registries: + - maven-alfresco-internal + schedule: + interval: "daily" + time: "22:00" + timezone: "Europe/London" + open-pull-requests-limit: 99 + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "monthly" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 20118e6..b326472 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,5 +14,5 @@ on: jobs: build_and_release: name: "Build and Release" - uses: Alfresco/alfresco-build-tools/.github/workflows/build-and-release-maven.yml@v7.0.0 + uses: Alfresco/alfresco-build-tools/.github/workflows/build-and-release-maven.yml@v8.4.0 secrets: inherit diff --git a/.gitignore b/.gitignore index dedf33f..97863b0 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,11 @@ hs_err_pid* # maven target/ +*.log.* +pom.xml.* +.flattened-pom.xml +.flattened-pom.xml.* +release.properties # IDE .classpath @@ -35,3 +40,8 @@ target/ .idea *.iml *.ipr +.gradle +.history + +# Mac +.DS_Store diff --git a/README.md b/README.md index caa460c..8e92aa2 100644 --- a/README.md +++ b/README.md @@ -1,48 +1,50 @@ ## Alfresco Content Services Event Model -[![Build Status](https://travis-ci.com/Alfresco/acs-event-model.svg?branch=master)](https://travis-ci.com/Alfresco/acs-event-model) + +[![Build Status](https://github.com/Alfresco/acs-event-model/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/Alfresco/acs-event-model/actions/workflows/ci.yml) Alfresco Content Services Event Model is a library packaged as a jar file which is part of [Alfresco Content Services Repository](https://community.alfresco.com/docs/DOC-6385-project-overview-repository). The library contains the events models and databind helpers to help the clients to marshall and unmarshall the events. ### Event Object -| Property | Type | Description | -|-----------------------|---------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `type` |String | The Alfresco event type. ([1.0 spec#type](https://github.com/cloudevents/spec/blob/v1.0/spec.md#type)) | -| `specversion` |String | The CloudEvents specification version. Value should be '1.0'. ([1.0 spec#specversion](https://github.com/cloudevents/spec/blob/v1.0/spec.md#specversion)) | -| `id` |String | Event ID, a UUID generated by the producer ([1.0 spec#id](https://github.com/cloudevents/spec/blob/v1.0/spec.md#id)) | -| `source` |URI-reference | The instance of a repository that produced the event, .i.e. repository cluster node identifier ([1.0 spec#source](https://github.com/cloudevents/spec/blob/v1.0/spec.md#source)) | -| `time` |Timestamp | The producer's timestamp of when the event occurred. ([1.0 spec#time](https://github.com/cloudevents/spec/blob/v1.0/spec.md#time)) | -| `dataschema` |URI-reference | Identifies the schema that data adheres to | -| `datacontenttype` |String | The content type of the data attribute. Value should be 'application/json'. ([1.0 spec#datacontenttype](https://github.com/cloudevents/spec/blob/v1.0/spec.md#datacontenttype)) | -| `data` |JSON | The domain-specific data of the event. ([1.0 spec#data](https://github.com/cloudevents/spec/blob/v1.0/spec.md#data-attribute)) | -| `data.eventGroupId` |String | Optional unique identifier for events group, i.e. a transaction ID | -| `data.resource` |Object (varies)| The object representing the resource affected | -| `data.resourceBefore` |Object (varies)| The object representing the old values of the changed resource's attributes. Note, this object is only available on the `Updated` event type | -| `extensionAttributes` |Object (varies)| (Optional) The object representing extension attributes (if any) that can be additionally added to the event. Note, this object will not be serialized if it is null. | | - +| Property | Type | Description | +|---------------------------------------|-----------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `type` | String | The Alfresco event type. ([1.0 spec#type](https://github.com/cloudevents/spec/blob/v1.0/spec.md#type)) | +| `specversion` | String | The CloudEvents specification version. Value should be '1.0'. ([1.0 spec#specversion](https://github.com/cloudevents/spec/blob/v1.0/spec.md#specversion)) | +| `id` | String | Event ID, a UUID generated by the producer ([1.0 spec#id](https://github.com/cloudevents/spec/blob/v1.0/spec.md#id)) | +| `source` | URI-reference | The instance of a repository that produced the event, .i.e. repository cluster node identifier ([1.0 spec#source](https://github.com/cloudevents/spec/blob/v1.0/spec.md#source)) | +| `time` | Timestamp | The producer's timestamp of when the event occurred. ([1.0 spec#time](https://github.com/cloudevents/spec/blob/v1.0/spec.md#time)) | +| `dataschema` | URI-reference | Identifies the schema that data adheres to | +| `datacontenttype` | String | The content type of the data attribute. Value should be 'application/json'. ([1.0 spec#datacontenttype](https://github.com/cloudevents/spec/blob/v1.0/spec.md#datacontenttype)) | +| `data` | JSON | The domain-specific data of the event. ([1.0 spec#data](https://github.com/cloudevents/spec/blob/v1.0/spec.md#data-attribute)) | +| `data.eventGroupId` | String | Optional unique identifier for events group, i.e. a transaction ID | +| `data.resource` | Object (varies) | The object representing the resource affected | +| `data.resourceBefore` | Object (varies) | The object representing the old values of the changed resource's attributes. Note, this object is only available on the `Updated` event type | +| `extensionAttributes` | Object (varies) | (Optional) The object representing extension attributes (if any) that can be additionally added to the event. Note, this object will not be serialized if it is null. | +| `data.resourceReaderAuthorities` | Array | The authority IDs that have READ access to the resource affected by the event. **Note:** this property will not be present in the event when `authorities generation` is disabled | +| `data.resourceDeniedAuthorities` | Array | The authority IDs that are denied READ access to the resource affected by the event. **Note:** this property will not be present in the event when `authorities generation` is disabled | +| `data.resourceReaderSecurityControls` | Array | The Governance security controls that have been placed on the resource affected by the event. **Note:** this property is only available for AGS. Also, it will not be present in the event response when `authorities generation` is disabled or AGS module is not installed | ### Resource Object -| Property | Type | Description | -|---------------------------------|---------------|------------------------------------------------------------------| -|`data.resource.id` |String |The unique ID of the resource, i.e. a node ID| -|`data.resource.primaryHierarchy` |Array |Optional primary hierarchy of ancestors of the resource affected, i.e. folder path for content. Note that the first element is the immediate parent| +| Property | Type | Description | +|----------------------------------|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------| +| `data.resource.id` | String | The unique ID of the resource, i.e. a node ID | +| `data.resource.primaryHierarchy` | Array | Optional primary hierarchy of ancestors of the resource affected, i.e. folder path for content. Note that the first element is the immediate parent | The rest of resource object attributes are self explanatory. See [JSON Schema](#json-schema) for the detailed view of the attributes' types. ### Event Types -| Name | Description | -|-----------------------------------|------------------------------------------------------------------| -| `org.alfresco.event.node.Created` | Occurs when a node is created | -| `org.alfresco.event.node.Updated` | Occurs when a node is updated or moved. Currently only node's name, type, properties, aspects, and content are supported| -| `org.alfresco.event.node.Deleted` | Occurs when a node is deleted | -| `org.alfresco.event.assoc.child.Created` | Occurs when a secondary child association is created | -| `org.alfresco.event.assoc.child.Deleted` | Occurs when a secondary child association is deleted | -| `org.alfresco.event.assoc.peer.Created` | Occurs when a peer association is created | -| `org.alfresco.event.assoc.peer.Deleted` | Occurs when a peer association is deleted | - +| Name | Description | +|------------------------------------------|--------------------------------------------------------------------------------------------------------------------------| +| `org.alfresco.event.node.Created` | Occurs when a node is created | +| `org.alfresco.event.node.Updated` | Occurs when a node is updated or moved. Currently only node's name, type, properties, aspects, and content are supported | +| `org.alfresco.event.node.Deleted` | Occurs when a node is deleted | +| `org.alfresco.event.assoc.child.Created` | Occurs when a secondary child association is created | +| `org.alfresco.event.assoc.child.Deleted` | Occurs when a secondary child association is deleted | +| `org.alfresco.event.assoc.peer.Created` | Occurs when a peer association is created | +| `org.alfresco.event.assoc.peer.Deleted` | Occurs when a peer association is deleted | ### JSON Schema @@ -94,6 +96,16 @@ For a detailed view of the event content refer to [Repo Event JSON schema](src/m "aspectNames": [ "cm:titled", "cm:auditable" + ], + "resourceReaderAuthorities": [ + "GROUP_EVERYONE", + "GROUP_site_u1privatesite", + "GROUP_site_u1privatesite_SiteConsumer" + ], + "resourceDeniedAuthorities": [], + "resourceReaderSecurityControls": [ + "e428663f-9171-42e2-b233-d8f2cd3f54f7:m6gFifJH", + "e428663f-9171-42e2-b233-d8f2cd3f54f7:mF2foUuA" ] } } @@ -178,7 +190,7 @@ For a detailed view of the event content refer to [Repo Event JSON schema](src/m } ``` -### Node updated event example - _content changed_ +### Node updated event example - _content changed_ ```json { @@ -247,7 +259,7 @@ For a detailed view of the event content refer to [Repo Event JSON schema](src/m } ``` -### Node updated event example - _content added_ +### Node updated event example - _content added_ ```json { @@ -314,7 +326,7 @@ For a detailed view of the event content refer to [Repo Event JSON schema](src/m } ``` -### Node updated event example - _node type changed_ +### Node updated event example - _node type changed_ ```json { @@ -378,7 +390,7 @@ For a detailed view of the event content refer to [Repo Event JSON schema](src/m } ``` -### Node updated event example - _property added_ +### Node updated event example - _property added_ ```json { @@ -448,7 +460,7 @@ For a detailed view of the event content refer to [Repo Event JSON schema](src/m } ``` -### Node updated event example - _property updated_ +### Node updated event example - _property updated_ ```json { @@ -818,14 +830,17 @@ For a detailed view of the event content refer to [Repo Event JSON schema](src/m ## Building and testing The project can be built and tested by running the following Maven command: + ~~~ mvn clean install ~~~ ### Artifacts + The artifact can be obtained by: -* downloading from [Alfresco repository](https://artifacts.alfresco.com/nexus/content/groups/public) +* downloading from [Alfresco repository](https://artifacts.alfresco.com/nexus/#browse/browse:public) * getting as Maven dependency by adding the dependency to your pom file: + ~~~ org.alfresco @@ -833,13 +848,16 @@ The artifact can be obtained by: version ~~~ + and Alfresco repository: + ~~~ alfresco-maven-repo https://artifacts.alfresco.com/nexus/content/groups/public ~~~ + **Note:** The SNAPSHOT version of the artifact is **never** published. @@ -858,18 +876,37 @@ RepoEvent> result = mapper.readValue(jsonString, new Typ If the event also has `extensionAttributes` that contains an extension object, then you can use the same mapper to deserialize the extension to its expected object: ```java - ExtensionAttributes resultExtensionAttributes = result.getExtensionAttributes(); - Object extValue = resultExtensionAttributes.getExtension("Your-Extension-Name"); - YOUR-OBJECT-TYPE obj = mapper.readValue(extValue.toString(), YOUR-OBJECT.class); +ExtensionAttributes resultExtensionAttributes = result.getExtensionAttributes(); +Object extValue = resultExtensionAttributes.getExtension("Your-Extension-Name"); +YOUR-OBJECT-TYPE obj = mapper.readValue(extValue.toString(), YOUR-OBJECT.class); ``` Other extension types (can only be one of the: **String**, **Number**, **Boolean**) can be retrieved directly without mapper. E.g. ```java - String myExt = (String) resultExtensionAttributes.getExtension("someStringExt"); +String myExt = (String) resultExtensionAttributes.getExtension("someStringExt"); ``` - ### Contributing guide -Please use [this guide](CONTRIBUTING.md) to make a contribution to the project. + +Thanks for your interest in contributing to this project! + +The following is a set of guidelines for contributing to this library. +Most of them will make the life of the reviewer easier and therefore decrease the time required for the patch be included in the next version. + +#### Code Quality + +This project uses spotless that enforces Alfresco formatting to ensure code quality. + +To check code-style violations you can use: + +```shell +mvn spotless:check +``` + +To reformat files you can use: + +```shell +mvn spotless:apply +``` diff --git a/pom.xml b/pom.xml index 9d6ac34..12875df 100644 --- a/pom.xml +++ b/pom.xml @@ -1,137 +1,204 @@ - 4.0.0 + 4.0.0 - - org.alfresco - alfresco-super-pom - 12 - + + org.alfresco + alfresco-super-pom + 12 + - acs-event-model - 1.0.1-SNAPSHOT - jar - acs-event-model - Alfresco Content Services Event Model + acs-event-model + 1.0.1-SNAPSHOT + jar + acs-event-model + Alfresco Content Services Event Model - - 17 - ${java.version} - ${java.version} - ${java.version} - ${java.version} - 2.17.2 + + scm:git:https://github.com/Alfresco/acs-event-model.git + scm:git:https://github.com/Alfresco/acs-event-model.git + HEAD + https://github.com/Alfresco/acs-event-model + - 4.12.2 - 2.0.1 - + + + alfresco-public + https://artifacts.alfresco.com/nexus/content/repositories/releases + + - - scm:git:https://github.com/Alfresco/acs-event-model.git - scm:git:https://github.com/Alfresco/acs-event-model.git - https://github.com/Alfresco/acs-event-model - HEAD - + + UTF-8 + UTF-8 - - - alfresco-public - https://artifacts.alfresco.com/nexus/content/repositories/releases - - + 17 + ${java.version} + ${java.version} + ${java.version} + ${java.version} - - - com.fasterxml.jackson.core - jackson-databind - ${jackson.version} - provided - + 4.12.2 + 2.0.1 - - - junit - junit - 4.13.1 - test - - - org.skyscreamer - jsonassert - 1.5.0 - test - - - commons-io - commons-io - 2.14.0 - test - + 2.18.0 + 5.11.3 + 2.17.0 + 1.5.3 + 3.4.2 + 2.43.0 + - - - com.fasterxml.jackson.module - jackson-module-jsonSchema - ${jackson.version} - test - - - com.github.victools - jsonschema-generator - ${jsonschema-generator.version} - test - - - com.github.victools - jsonschema-module-jackson - ${jsonschema-generator.version} - test - - - org.slf4j - slf4j-simple - 1.7.30 - test - - + + + com.fasterxml.jackson.core + jackson-databind + ${dependency.jackson.version} + provided + - - - - org.codehaus.mojo - license-maven-plugin - ${license-maven-plugin.version} - - - third-party-licenses - - add-third-party - - generate-resources - - true - provided,test - org.alfresco - true - https://raw.githubusercontent.com/Alfresco/third-party-license-overrides/master/includedLicenses.txt - https://raw.githubusercontent.com/Alfresco/third-party-license-overrides/master/licenseMerges.txt - https://raw.githubusercontent.com/Alfresco/third-party-license-overrides/master/override-THIRD-PARTY.properties - - - - - - org.apache.maven.plugins - maven-jar-plugin - 3.0.2 - - - - test-jar - - - - - - + + + org.junit.jupiter + junit-jupiter + ${dependency.junit-jupiter.version} + test + + + org.skyscreamer + jsonassert + ${dependency.jsonassert.version} + test + + + commons-io + commons-io + ${dependency.commons-io.version} + test + + + + + com.fasterxml.jackson.module + jackson-module-jsonSchema + ${dependency.jackson.version} + test + + + com.github.victools + jsonschema-generator + ${jsonschema-generator.version} + test + + + com.github.victools + jsonschema-module-jackson + ${jsonschema-generator.version} + test + + + + + + + org.codehaus.mojo + license-maven-plugin + ${license-maven-plugin.version} + + + third-party-licenses + + add-third-party + + generate-resources + + true + provided,test + org.alfresco + true + https://raw.githubusercontent.com/Alfresco/third-party-license-overrides/master/includedLicenses.txt + https://raw.githubusercontent.com/Alfresco/third-party-license-overrides/master/licenseMerges.txt + https://raw.githubusercontent.com/Alfresco/third-party-license-overrides/master/override-THIRD-PARTY.properties + + + + + + org.apache.maven.plugins + maven-jar-plugin + ${dependency.maven-jar-plugin.version} + + + + test-jar + + + + + + org.codehaus.mojo + flatten-maven-plugin + + minimum + + + + flatten + + flatten + + process-resources + + + flatten.clean + + clean + + clean + + + + + com.diffplug.spotless + spotless-maven-plugin + ${dependency.spotless-maven-plugin.version} + + + + https://raw.githubusercontent.com/Alfresco/alfresco-community-repo/refs/heads/master/alfresco-formatter.xml + + + \#java|\#javax|\#jakarta,\#,\#org.alfresco,java|javax|jakarta,,org.alfresco + + + + + + + pom.xml + + + false + true + + + + + *.md + + + + + + + + check + + compile + + + + + + diff --git a/src/main/java/org/alfresco/repo/event/EventAttributes.java b/src/main/java/org/alfresco/repo/event/EventAttributes.java index b9c7c75..7cadc67 100644 --- a/src/main/java/org/alfresco/repo/event/EventAttributes.java +++ b/src/main/java/org/alfresco/repo/event/EventAttributes.java @@ -31,8 +31,7 @@ import org.alfresco.repo.event.extension.ExtensionAttributes; /** - * Event's attributes conforming to - * CloudEvents v1.0 specification. + * Event's attributes conforming to CloudEvents v1.0 specification. * * @author Jamal Kaabi-Mofrad */ @@ -49,8 +48,7 @@ public interface EventAttributes String getType(); /** - * @return The context in which an event happened. - * E.g. The instance of a DBP component that produced the event. + * @return The context in which an event happened. E.g. The instance of a DBP component that produced the event. */ URI getSource(); @@ -70,15 +68,13 @@ public interface EventAttributes ZonedDateTime getTime(); /** - * @return The content type of the data attribute adhering - * to the RFC2046 + * @return The content type of the data attribute adhering to the RFC2046 */ String getDatacontenttype(); /** - * @return Optional extension attributes that can be additionally added to the event. - *
- * See CloudEvents v1.0 specification Extension Context Attributes for more details. + * @return Optional extension attributes that can be additionally added to the event.
+ * See CloudEvents v1.0 specification Extension Context Attributes for more details. */ default ExtensionAttributes getExtensionAttributes() { diff --git a/src/main/java/org/alfresco/repo/event/databind/DateSerializer.java b/src/main/java/org/alfresco/repo/event/databind/DateSerializer.java index 552734e..2961e23 100644 --- a/src/main/java/org/alfresco/repo/event/databind/DateSerializer.java +++ b/src/main/java/org/alfresco/repo/event/databind/DateSerializer.java @@ -15,15 +15,15 @@ */ package org.alfresco.repo.event.databind; -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.ser.std.StdSerializer; - import java.io.IOException; import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.util.Date; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; + public class DateSerializer extends StdSerializer { @@ -41,7 +41,7 @@ public void serialize(Date date, JsonGenerator jsonGenerator, SerializerProvider throws IOException { ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(date.toInstant(), ZoneOffset.UTC); - //delegating the formatting to the DateTimeSerializer in order to apply the same strategy + // delegating the formatting to the DateTimeSerializer in order to apply the same strategy dateTimeSerializer.serialize(zonedDateTime, jsonGenerator, serializerProvider); } } diff --git a/src/main/java/org/alfresco/repo/event/databind/DateTimeDeserializer.java b/src/main/java/org/alfresco/repo/event/databind/DateTimeDeserializer.java index 602a89e..934ab3e 100644 --- a/src/main/java/org/alfresco/repo/event/databind/DateTimeDeserializer.java +++ b/src/main/java/org/alfresco/repo/event/databind/DateTimeDeserializer.java @@ -55,7 +55,7 @@ public DateTimeDeserializer(Class valueClass) @Override public ZonedDateTime deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) - throws IOException + throws IOException { try { diff --git a/src/main/java/org/alfresco/repo/event/databind/DateTimeSerializer.java b/src/main/java/org/alfresco/repo/event/databind/DateTimeSerializer.java index f9d3b5c..efaacd0 100644 --- a/src/main/java/org/alfresco/repo/event/databind/DateTimeSerializer.java +++ b/src/main/java/org/alfresco/repo/event/databind/DateTimeSerializer.java @@ -55,7 +55,7 @@ protected DateTimeSerializer(Class t, boolean dummy) @Override public void serialize(ZonedDateTime zonedDateTime, JsonGenerator jsonGenerator, - SerializerProvider serializerProvider) throws IOException + SerializerProvider serializerProvider) throws IOException { jsonGenerator.writeString(zonedDateTime.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)); } diff --git a/src/main/java/org/alfresco/repo/event/databind/ExtensionDeserializer.java b/src/main/java/org/alfresco/repo/event/databind/ExtensionDeserializer.java index 4d7bcfb..8e1cbb3 100644 --- a/src/main/java/org/alfresco/repo/event/databind/ExtensionDeserializer.java +++ b/src/main/java/org/alfresco/repo/event/databind/ExtensionDeserializer.java @@ -27,15 +27,15 @@ import java.io.IOException; -import org.alfresco.repo.event.extension.ExtensionAttributes; -import org.alfresco.repo.event.extension.ExtensionAttributesImpl; - import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.ObjectCodec; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonNode; +import org.alfresco.repo.event.extension.ExtensionAttributes; +import org.alfresco.repo.event.extension.ExtensionAttributesImpl; + /** * Custom Jackson deserializer for the {@link ExtensionAttributes} type. * @@ -44,8 +44,7 @@ public class ExtensionDeserializer extends JsonDeserializer { public ExtensionDeserializer() - { - } + {} @Override public ExtensionAttributes deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException @@ -61,21 +60,19 @@ public ExtensionAttributes deserialize(JsonParser parser, DeserializationContext switch (extValue.getNodeType()) { - case STRING: - extension.addExtension(extName, extValue.textValue()); - break; - case NUMBER: - extension.addExtension(extName, extValue.numberValue()); - break; - case BOOLEAN: - extension.addExtension(extName, extValue.booleanValue()); - break; - default: - extension.addExtension(extName, extValue.toString()); + case STRING: + extension.addExtension(extName, extValue.textValue()); + break; + case NUMBER: + extension.addExtension(extName, extValue.numberValue()); + break; + case BOOLEAN: + extension.addExtension(extName, extValue.booleanValue()); + break; + default: + extension.addExtension(extName, extValue.toString()); } }); return extension; } } - - diff --git a/src/main/java/org/alfresco/repo/event/databind/ExtensionSerializer.java b/src/main/java/org/alfresco/repo/event/databind/ExtensionSerializer.java index ba1f855..d7e0433 100644 --- a/src/main/java/org/alfresco/repo/event/databind/ExtensionSerializer.java +++ b/src/main/java/org/alfresco/repo/event/databind/ExtensionSerializer.java @@ -27,12 +27,12 @@ import java.io.IOException; -import org.alfresco.repo.event.extension.ExtensionAttributes; - import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.ser.std.StdSerializer; +import org.alfresco.repo.event.extension.ExtensionAttributes; + /** * Custom Jackson serializer for the {@link ExtensionAttributes} type. * @@ -47,7 +47,7 @@ protected ExtensionSerializer() @Override public void serialize(ExtensionAttributes eventExtension, JsonGenerator jsonGenerator, - SerializerProvider serializerProvider) throws IOException + SerializerProvider serializerProvider) throws IOException { jsonGenerator.writeStartObject(); for (String ext : eventExtension.getExtensionNames()) @@ -59,5 +59,3 @@ public void serialize(ExtensionAttributes eventExtension, JsonGenerator jsonGene jsonGenerator.writeEndObject(); } } - - diff --git a/src/main/java/org/alfresco/repo/event/databind/ObjectMapperFactory.java b/src/main/java/org/alfresco/repo/event/databind/ObjectMapperFactory.java index e4621ba..c9464e7 100644 --- a/src/main/java/org/alfresco/repo/event/databind/ObjectMapperFactory.java +++ b/src/main/java/org/alfresco/repo/event/databind/ObjectMapperFactory.java @@ -25,20 +25,21 @@ */ package org.alfresco.repo.event.databind; +import java.time.ZonedDateTime; +import java.util.Date; + import com.fasterxml.jackson.core.Version; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.module.SimpleAbstractTypeResolver; import com.fasterxml.jackson.databind.module.SimpleModule; + +import org.alfresco.repo.event.extension.ExtensionAttributes; +import org.alfresco.repo.event.extension.ExtensionAttributesImpl; import org.alfresco.repo.event.v1.model.DataAttributes; import org.alfresco.repo.event.v1.model.EventData; import org.alfresco.repo.event.v1.model.Resource; -import org.alfresco.repo.event.extension.ExtensionAttributes; -import org.alfresco.repo.event.extension.ExtensionAttributesImpl; - -import java.time.ZonedDateTime; -import java.util.Date; /** * Repo Event object factory. @@ -61,10 +62,9 @@ public ObjectMapper createObjectMapper() final SimpleModule module = getSimpleModule(); final SimpleAbstractTypeResolver resolver = getSimpleAbstractTypeResolver(); - if(resolver != null) + if (resolver != null) { - // add the extension when creating the Mapper. As 'getSimpleAbstractTypeResolver' can be - // overridden by enterprise code. + // add the extension when creating the Mapper. resolver.addMapping(ExtensionAttributes.class, ExtensionAttributesImpl.class); module.setAbstractTypes(resolver); } @@ -75,8 +75,7 @@ public ObjectMapper createObjectMapper() protected SimpleModule getSimpleModule() { - final SimpleModule module = - new SimpleModule("Resource Serializer-Deserializer", new Version(0, 1, 0, "", "", "")); + final SimpleModule module = new SimpleModule("Resource Serializer-Deserializer", new Version(0, 1, 0, "", "", "")); module.addSerializer(ZonedDateTime.class, new DateTimeSerializer()); module.addDeserializer(ZonedDateTime.class, new DateTimeDeserializer()); module.addSerializer(Date.class, new DateSerializer()); diff --git a/src/main/java/org/alfresco/repo/event/databind/ResourceDeserializer.java b/src/main/java/org/alfresco/repo/event/databind/ResourceDeserializer.java index 5207722..5ef5c88 100644 --- a/src/main/java/org/alfresco/repo/event/databind/ResourceDeserializer.java +++ b/src/main/java/org/alfresco/repo/event/databind/ResourceDeserializer.java @@ -28,11 +28,6 @@ import java.io.IOException; import java.util.Map; -import org.alfresco.repo.event.v1.model.ChildAssociationResource; -import org.alfresco.repo.event.v1.model.NodeResource; -import org.alfresco.repo.event.v1.model.PeerAssociationResource; -import org.alfresco.repo.event.v1.model.Resource; - import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.ObjectCodec; import com.fasterxml.jackson.core.TreeNode; @@ -41,20 +36,24 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.TextNode; +import org.alfresco.repo.event.v1.model.ChildAssociationResource; +import org.alfresco.repo.event.v1.model.NodeResource; +import org.alfresco.repo.event.v1.model.PeerAssociationResource; +import org.alfresco.repo.event.v1.model.Resource; + /** * @author Jamal Kaabi-Mofrad */ public class ResourceDeserializer extends JsonDeserializer { - private static final String TYPE_FIELD = "@type"; - private static final Map> TYPE_MAP = Map.of( - getName(NodeResource.class), NodeResource.class, - getName(ChildAssociationResource.class), ChildAssociationResource.class, - getName(PeerAssociationResource.class), PeerAssociationResource.class); + private static final String TYPE_FIELD = "@type"; + private static final Map> TYPE_MAP = Map.of( + getName(NodeResource.class), NodeResource.class, + getName(ChildAssociationResource.class), ChildAssociationResource.class, + getName(PeerAssociationResource.class), PeerAssociationResource.class); public ResourceDeserializer() - { - } + {} private static String getName(Class aClass) { diff --git a/src/main/java/org/alfresco/repo/event/extension/ExtensionAttributes.java b/src/main/java/org/alfresco/repo/event/extension/ExtensionAttributes.java index 2e7d625..3aa6ec5 100644 --- a/src/main/java/org/alfresco/repo/event/extension/ExtensionAttributes.java +++ b/src/main/java/org/alfresco/repo/event/extension/ExtensionAttributes.java @@ -36,15 +36,15 @@ public interface ExtensionAttributes { /** - * Gets the extension value. The value's type can only be one of the following types: - *
+ * Gets the extension value. The value's type can only be one of the following types:
*
    - *
  • String
  • - *
  • Number
  • - *
  • Boolean
  • + *
  • String
  • + *
  • Number
  • + *
  • Boolean
  • *
* - * @param extensionName the extension name (i.e. Json field name) + * @param extensionName + * the extension name (i.e. Json field name) * @return the extension value */ Object getExtension(String extensionName); @@ -52,8 +52,10 @@ public interface ExtensionAttributes /** * Adds extension * - * @param extensionName the extension name (i.e. key) - * @param extension the extension value + * @param extensionName + * the extension name (i.e. key) + * @param extension + * the extension value */ void addExtension(String extensionName, Object extension); diff --git a/src/main/java/org/alfresco/repo/event/extension/ExtensionAttributesImpl.java b/src/main/java/org/alfresco/repo/event/extension/ExtensionAttributesImpl.java index bba3a28..6f31a11 100644 --- a/src/main/java/org/alfresco/repo/event/extension/ExtensionAttributesImpl.java +++ b/src/main/java/org/alfresco/repo/event/extension/ExtensionAttributesImpl.java @@ -30,12 +30,12 @@ import java.util.Objects; import java.util.Set; -import org.alfresco.repo.event.databind.ExtensionDeserializer; -import org.alfresco.repo.event.databind.ExtensionSerializer; - import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import org.alfresco.repo.event.databind.ExtensionDeserializer; +import org.alfresco.repo.event.databind.ExtensionSerializer; + /** * @author Jamal Kaabi-Mofrad */ diff --git a/src/main/java/org/alfresco/repo/event/util/NodeResourceUtils.java b/src/main/java/org/alfresco/repo/event/util/NodeResourceUtils.java index abbb559..ddc7eed 100644 --- a/src/main/java/org/alfresco/repo/event/util/NodeResourceUtils.java +++ b/src/main/java/org/alfresco/repo/event/util/NodeResourceUtils.java @@ -26,39 +26,42 @@ package org.alfresco.repo.event.util; -import org.alfresco.repo.event.v1.model.NodeResource; - import java.util.Objects; +import org.alfresco.repo.event.v1.model.NodeResource; + public final class NodeResourceUtils { - private NodeResourceUtils() {} + private NodeResourceUtils() + {} - /** - * From a NodeResource, creates a NodeResource.Builder filled with all NodeResource information - * - * @param nodeResource to be used to copy information from - * @return a NodeResource.Builder filled with nodeResource information - */ - public static NodeResource.Builder getFilledBuilder( NodeResource nodeResource ) { - Objects.requireNonNull(nodeResource); + /** + * From a NodeResource, creates a NodeResource.Builder filled with all NodeResource information + * + * @param nodeResource + * to be used to copy information from + * @return a NodeResource.Builder filled with nodeResource information + */ + public static NodeResource.Builder getFilledBuilder(NodeResource nodeResource) + { + Objects.requireNonNull(nodeResource); - return new NodeResource.Builder() - .setAspectNames(nodeResource.getAspectNames()) - .setContent(nodeResource.getContent()) - .setCreatedAt(nodeResource.getCreatedAt()) - .setId(nodeResource.getId()) - .setIsFile(nodeResource.isFile()) - .setCreatedByUser(nodeResource.getCreatedByUser()) - .setIsFolder(nodeResource.isFolder()) - .setLocalizedProperties(nodeResource.getLocalizedProperties()) - .setModifiedAt(nodeResource.getModifiedAt()) - .setModifiedByUser(nodeResource.getModifiedByUser()) - .setName(nodeResource.getName()) - .setNodeType(nodeResource.getNodeType()) - .setPrimaryAssocQName(nodeResource.getPrimaryAssocQName()) - .setPrimaryHierarchy(nodeResource.getPrimaryHierarchy()) - .setProperties(nodeResource.getProperties()) - .setSecondaryParents(nodeResource.getSecondaryParents()); - } + return new NodeResource.Builder() + .setAspectNames(nodeResource.getAspectNames()) + .setContent(nodeResource.getContent()) + .setCreatedAt(nodeResource.getCreatedAt()) + .setId(nodeResource.getId()) + .setIsFile(nodeResource.isFile()) + .setCreatedByUser(nodeResource.getCreatedByUser()) + .setIsFolder(nodeResource.isFolder()) + .setLocalizedProperties(nodeResource.getLocalizedProperties()) + .setModifiedAt(nodeResource.getModifiedAt()) + .setModifiedByUser(nodeResource.getModifiedByUser()) + .setName(nodeResource.getName()) + .setNodeType(nodeResource.getNodeType()) + .setPrimaryAssocQName(nodeResource.getPrimaryAssocQName()) + .setPrimaryHierarchy(nodeResource.getPrimaryHierarchy()) + .setProperties(nodeResource.getProperties()) + .setSecondaryParents(nodeResource.getSecondaryParents()); + } } diff --git a/src/main/java/org/alfresco/repo/event/v1/model/AbstractNodeResource.java b/src/main/java/org/alfresco/repo/event/v1/model/AbstractNodeResource.java index b0d0097..2cbdb6e 100644 --- a/src/main/java/org/alfresco/repo/event/v1/model/AbstractNodeResource.java +++ b/src/main/java/org/alfresco/repo/event/v1/model/AbstractNodeResource.java @@ -78,7 +78,7 @@ public boolean equals(Object o) } AbstractNodeResource resource = (AbstractNodeResource) o; return Objects.equals(id, resource.id) - && Objects.equals(primaryHierarchy, resource.primaryHierarchy); + && Objects.equals(primaryHierarchy, resource.primaryHierarchy); } @Override diff --git a/src/main/java/org/alfresco/repo/event/v1/model/ChildAssocInfo.java b/src/main/java/org/alfresco/repo/event/v1/model/ChildAssocInfo.java index c16c94d..784814c 100644 --- a/src/main/java/org/alfresco/repo/event/v1/model/ChildAssocInfo.java +++ b/src/main/java/org/alfresco/repo/event/v1/model/ChildAssocInfo.java @@ -35,8 +35,7 @@ public class ChildAssocInfo private String id; public ChildAssocInfo() - { - } + {} public ChildAssocInfo(String id) { diff --git a/src/main/java/org/alfresco/repo/event/v1/model/ChildAssociationResource.java b/src/main/java/org/alfresco/repo/event/v1/model/ChildAssociationResource.java index 7dbb8a1..3cdc029 100644 --- a/src/main/java/org/alfresco/repo/event/v1/model/ChildAssociationResource.java +++ b/src/main/java/org/alfresco/repo/event/v1/model/ChildAssociationResource.java @@ -60,7 +60,7 @@ public ChildAssocInfo getChild() return child; } - public String getAssocQName() + public String getAssocQName() { return assocQName; } @@ -95,10 +95,10 @@ public String toString() { final StringBuilder sb = new StringBuilder(100); sb.append("ChildAssociationResource [parent=").append(parent) - .append(", child=").append(child) - .append(", assocType=").append(assocType) - .append(", assocQName=").append(assocQName) - .append(']'); + .append(", child=").append(child) + .append(", assocType=").append(assocType) + .append(", assocQName=").append(assocQName) + .append(']'); return sb.toString(); } } diff --git a/src/main/java/org/alfresco/repo/event/v1/model/ContentInfo.java b/src/main/java/org/alfresco/repo/event/v1/model/ContentInfo.java index d863412..07e2307 100644 --- a/src/main/java/org/alfresco/repo/event/v1/model/ContentInfo.java +++ b/src/main/java/org/alfresco/repo/event/v1/model/ContentInfo.java @@ -33,16 +33,15 @@ /** * @author Jamal Kaabi-Mofrad */ -@JsonInclude (Include.NON_NULL) +@JsonInclude(Include.NON_NULL) public class ContentInfo { private String mimeType; - private Long sizeInBytes; + private Long sizeInBytes; private String encoding; public ContentInfo() - { - } + {} public ContentInfo(String mimeType, Long sizeInBytes, String encoding) { @@ -79,8 +78,8 @@ public boolean equals(Object o) } ContentInfo that = (ContentInfo) o; return Objects.equals(mimeType, that.mimeType) - && Objects.equals(sizeInBytes, that.sizeInBytes) - && Objects.equals(encoding, that.encoding); + && Objects.equals(sizeInBytes, that.sizeInBytes) + && Objects.equals(encoding, that.encoding); } @Override @@ -94,9 +93,9 @@ public String toString() { final StringBuilder sb = new StringBuilder(100); sb.append("ContentInfo [mimeType=").append(mimeType) - .append(", sizeInBytes=").append(sizeInBytes) - .append(", encoding=").append(encoding) - .append(']'); + .append(", sizeInBytes=").append(sizeInBytes) + .append(", encoding=").append(encoding) + .append(']'); return sb.toString(); } } diff --git a/src/main/java/org/alfresco/repo/event/v1/model/EventData.java b/src/main/java/org/alfresco/repo/event/v1/model/EventData.java index 864e963..4aa11b7 100644 --- a/src/main/java/org/alfresco/repo/event/v1/model/EventData.java +++ b/src/main/java/org/alfresco/repo/event/v1/model/EventData.java @@ -159,9 +159,9 @@ public String toString() public static class Builder { - private String eventGroupId; - private R resource; - private R resourceBefore; + private String eventGroupId; + private R resource; + private R resourceBefore; private Set resourceReaderAuthorities; private Set resourceDeniedAuthorities; private Set resourceReaderSecurityControls; diff --git a/src/main/java/org/alfresco/repo/event/v1/model/EventType.java b/src/main/java/org/alfresco/repo/event/v1/model/EventType.java index 39dd357..1dff24f 100644 --- a/src/main/java/org/alfresco/repo/event/v1/model/EventType.java +++ b/src/main/java/org/alfresco/repo/event/v1/model/EventType.java @@ -32,10 +32,7 @@ */ public enum EventType { - NODE_CREATED(EventTypeConst.CREATED, ContextType.NODE), NODE_UPDATED(EventTypeConst.UPDATED, ContextType.NODE), NODE_DELETED(EventTypeConst.DELETED, ContextType.NODE), - CHILD_ASSOC_CREATED(EventTypeConst.CREATED, ContextType.CHILD_ASSOC), CHILD_ASSOC_DELETED(EventTypeConst.DELETED, ContextType.CHILD_ASSOC), - PEER_ASSOC_CREATED(EventTypeConst.CREATED, ContextType.PEER_ASSOC), PEER_ASSOC_DELETED(EventTypeConst.DELETED, ContextType.PEER_ASSOC), - PERMISSION_UPDATED(EventTypeConst.UPDATED, ContextType.PERMISSION); + NODE_CREATED(EventTypeConst.CREATED, ContextType.NODE), NODE_UPDATED(EventTypeConst.UPDATED, ContextType.NODE), NODE_DELETED(EventTypeConst.DELETED, ContextType.NODE), CHILD_ASSOC_CREATED(EventTypeConst.CREATED, ContextType.CHILD_ASSOC), CHILD_ASSOC_DELETED(EventTypeConst.DELETED, ContextType.CHILD_ASSOC), PEER_ASSOC_CREATED(EventTypeConst.CREATED, ContextType.PEER_ASSOC), PEER_ASSOC_DELETED(EventTypeConst.DELETED, ContextType.PEER_ASSOC), PERMISSION_UPDATED(EventTypeConst.UPDATED, ContextType.PERMISSION); private static final String PREFIX = "org.alfresco.event."; private final String type; @@ -43,19 +40,19 @@ public enum EventType EventType(String type, ContextType contextType) { - this.type = type; - this.contextType = contextType; + this.type = type; + this.contextType = contextType; } - /* package*/ String getContext() + /* package */ String getContext() { - return contextType.getContext(); + return contextType.getContext(); } @Override public String toString() { - return PREFIX + getContext() + type; + return PREFIX + getContext() + type; } /** @@ -73,15 +70,16 @@ private enum ContextType NODE("node."), CHILD_ASSOC("assoc.child."), PEER_ASSOC("assoc.peer."), PERMISSION("permission."); private final String context; + ContextType(String context) { this.context = context; } String getContext() - { - return context; - } + { + return context; + } } private static class EventTypeConst @@ -91,4 +89,3 @@ private static class EventTypeConst private static final String DELETED = "Deleted"; } } - diff --git a/src/main/java/org/alfresco/repo/event/v1/model/NodeResource.java b/src/main/java/org/alfresco/repo/event/v1/model/NodeResource.java index 7021677..989b31b 100644 --- a/src/main/java/org/alfresco/repo/event/v1/model/NodeResource.java +++ b/src/main/java/org/alfresco/repo/event/v1/model/NodeResource.java @@ -29,7 +29,6 @@ import java.io.Serializable; import java.time.ZonedDateTime; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Objects; @@ -42,8 +41,7 @@ import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; /** - * Represents Alfresco node resource. - * Any attribute that its value is null, will not be serialized. + * Represents Alfresco node resource. Any attribute that its value is null, will not be serialized. * * @author Jamal Kaabi-Mofrad */ @@ -51,20 +49,20 @@ @JsonDeserialize(builder = NodeResource.Builder.class) public class NodeResource extends AbstractNodeResource { - private final String name; - private final String nodeType; - private final Boolean isFile; - private final Boolean isFolder; - private final UserInfo createdByUser; - private final ZonedDateTime createdAt; - private final UserInfo modifiedByUser; - private final ZonedDateTime modifiedAt; - private final ContentInfo content; - private final Map properties; - private final Map> localizedProperties; - private final Set aspectNames; - private final String primaryAssocQName; - private final List secondaryParents; + private final String name; + private final String nodeType; + private final Boolean isFile; + private final Boolean isFolder; + private final UserInfo createdByUser; + private final ZonedDateTime createdAt; + private final UserInfo modifiedByUser; + private final ZonedDateTime modifiedAt; + private final ContentInfo content; + private final Map properties; + private final Map> localizedProperties; + private final Set aspectNames; + private final String primaryAssocQName; + private final List secondaryParents; private NodeResource(Builder builder) { @@ -152,7 +150,8 @@ public Set getAspectNames() return aspectNames; } - public String getPrimaryAssocQName() { + public String getPrimaryAssocQName() + { return primaryAssocQName; } @@ -178,26 +177,26 @@ public boolean equals(Object o) } NodeResource that = (NodeResource) o; return Objects.equals(name, that.name) - && Objects.equals(nodeType, that.nodeType) - && Objects.equals(isFile, that.isFile) - && Objects.equals(isFolder, that.isFolder) - && Objects.equals(createdByUser, that.createdByUser) - && Objects.equals(createdAt, that.createdAt) - && Objects.equals(modifiedByUser, that.modifiedByUser) - && Objects.equals(modifiedAt, that.modifiedAt) - && Objects.equals(content, that.content) - && Objects.equals(properties, that.properties) - && Objects.equals(localizedProperties, that.localizedProperties) - && Objects.equals(aspectNames, that.aspectNames) - && Objects.equals(secondaryParents, that.secondaryParents); + && Objects.equals(nodeType, that.nodeType) + && Objects.equals(isFile, that.isFile) + && Objects.equals(isFolder, that.isFolder) + && Objects.equals(createdByUser, that.createdByUser) + && Objects.equals(createdAt, that.createdAt) + && Objects.equals(modifiedByUser, that.modifiedByUser) + && Objects.equals(modifiedAt, that.modifiedAt) + && Objects.equals(content, that.content) + && Objects.equals(properties, that.properties) + && Objects.equals(localizedProperties, that.localizedProperties) + && Objects.equals(aspectNames, that.aspectNames) + && Objects.equals(secondaryParents, that.secondaryParents); } @Override public int hashCode() { return Objects.hash(super.hashCode(), name, nodeType, isFile, isFolder, createdByUser, - createdAt, modifiedByUser, modifiedAt, content, properties, - localizedProperties, aspectNames, primaryAssocQName, secondaryParents); + createdAt, modifiedByUser, modifiedAt, content, properties, + localizedProperties, aspectNames, primaryAssocQName, secondaryParents); } @Override @@ -205,22 +204,22 @@ public String toString() { final StringBuilder sb = new StringBuilder(500); sb.append("NodeResource [id=").append(id) - .append(", name=").append(name) - .append(", nodeType=").append(nodeType) - .append(", isFile=").append(isFile) - .append(", isFolder=").append(isFolder) - .append(", createdByUser=").append(createdByUser) - .append(", createdAt=").append(createdAt) - .append(", modifiedByUser=").append(modifiedByUser) - .append(", modifiedAt=").append(modifiedAt) - .append(", content=").append(content) - .append(", properties=").append(properties) - .append(", localizedProperties=").append(localizedProperties) - .append(", aspectNames=").append(aspectNames) - .append(", primaryHierarchy=").append(primaryHierarchy) - .append(", primaryAssocQName=").append(primaryAssocQName) - .append(", secondaryParents=").append(secondaryParents) - .append(']'); + .append(", name=").append(name) + .append(", nodeType=").append(nodeType) + .append(", isFile=").append(isFile) + .append(", isFolder=").append(isFolder) + .append(", createdByUser=").append(createdByUser) + .append(", createdAt=").append(createdAt) + .append(", modifiedByUser=").append(modifiedByUser) + .append(", modifiedAt=").append(modifiedAt) + .append(", content=").append(content) + .append(", properties=").append(properties) + .append(", localizedProperties=").append(localizedProperties) + .append(", aspectNames=").append(aspectNames) + .append(", primaryHierarchy=").append(primaryHierarchy) + .append(", primaryAssocQName=").append(primaryAssocQName) + .append(", secondaryParents=").append(secondaryParents) + .append(']'); return sb.toString(); } @@ -231,31 +230,31 @@ public String toString() @JsonPOJOBuilder(withPrefix = "set") public static class Builder { - private String id; - private String name; - private String nodeType; - private Boolean isFile; - private Boolean isFolder; - private UserInfo createdByUser; - private ZonedDateTime createdAt; - private UserInfo modifiedByUser; - private ZonedDateTime modifiedAt; - private List primaryHierarchy; - private ContentInfo content; - private Map properties; - private Map> localizedProperties; - private Set aspectNames; - private String primaryAssocQName; - private List secondaryParents; + private String id; + private String name; + private String nodeType; + private Boolean isFile; + private Boolean isFolder; + private UserInfo createdByUser; + private ZonedDateTime createdAt; + private UserInfo modifiedByUser; + private ZonedDateTime modifiedAt; + private List primaryHierarchy; + private ContentInfo content; + private Map properties; + private Map> localizedProperties; + private Set aspectNames; + private String primaryAssocQName; + private List secondaryParents; public Builder() - { - } + {} /** * Copy builder * - * @param that existing {@code Builder} object + * @param that + * existing {@code Builder} object */ public Builder(Builder that) { diff --git a/src/main/java/org/alfresco/repo/event/v1/model/PeerAssocInfo.java b/src/main/java/org/alfresco/repo/event/v1/model/PeerAssocInfo.java index 1583efc..69620bf 100644 --- a/src/main/java/org/alfresco/repo/event/v1/model/PeerAssocInfo.java +++ b/src/main/java/org/alfresco/repo/event/v1/model/PeerAssocInfo.java @@ -36,8 +36,7 @@ public class PeerAssocInfo private String id; public PeerAssocInfo() - { - } + {} public PeerAssocInfo(String id) { diff --git a/src/main/java/org/alfresco/repo/event/v1/model/PeerAssociationResource.java b/src/main/java/org/alfresco/repo/event/v1/model/PeerAssociationResource.java index d368823..44c1221 100644 --- a/src/main/java/org/alfresco/repo/event/v1/model/PeerAssociationResource.java +++ b/src/main/java/org/alfresco/repo/event/v1/model/PeerAssociationResource.java @@ -87,9 +87,9 @@ public String toString() { final StringBuilder sb = new StringBuilder(100); sb.append("PeerAssociationResource [source=").append(source) - .append(", target=").append(target) - .append(", assocType=").append(assocType) - .append(']'); + .append(", target=").append(target) + .append(", assocType=").append(assocType) + .append(']'); return sb.toString(); } } diff --git a/src/main/java/org/alfresco/repo/event/v1/model/RepoEvent.java b/src/main/java/org/alfresco/repo/event/v1/model/RepoEvent.java index d3d82cd..a00d9ea 100644 --- a/src/main/java/org/alfresco/repo/event/v1/model/RepoEvent.java +++ b/src/main/java/org/alfresco/repo/event/v1/model/RepoEvent.java @@ -29,14 +29,14 @@ import java.time.ZonedDateTime; import java.util.Objects; -import org.alfresco.repo.event.EventAttributes; -import org.alfresco.repo.event.extension.ExtensionAttributes; - import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import org.alfresco.repo.event.EventAttributes; +import org.alfresco.repo.event.extension.ExtensionAttributes; + /** * Represents Alfresco event. * @@ -48,13 +48,13 @@ public class RepoEvent> implements private static final String SPEC_VERSION = "1.0"; private static final String CONTENT_TYPE = "application/json"; - private final String specversion; - private final String type; - private final String id; - private final URI source; + private final String specversion; + private final String type; + private final String id; + private final URI source; private final ZonedDateTime time; - private final URI dataschema; - private final String datacontenttype; + private final URI dataschema; + private final String datacontenttype; private final D data; private final ExtensionAttributes extensionAttributes; @@ -144,14 +144,14 @@ public boolean equals(Object o) } RepoEvent repoEvent = (RepoEvent) o; return Objects.equals(specversion, repoEvent.specversion) - && Objects.equals(type, repoEvent.type) - && Objects.equals(id, repoEvent.id) - && Objects.equals(source, repoEvent.source) - && Objects.equals(dataschema, repoEvent.dataschema) - && Objects.equals(time, repoEvent.time) - && Objects.equals(datacontenttype, repoEvent.datacontenttype) - && Objects.equals(data, repoEvent.data) - && Objects.equals(extensionAttributes, repoEvent.extensionAttributes); + && Objects.equals(type, repoEvent.type) + && Objects.equals(id, repoEvent.id) + && Objects.equals(source, repoEvent.source) + && Objects.equals(dataschema, repoEvent.dataschema) + && Objects.equals(time, repoEvent.time) + && Objects.equals(datacontenttype, repoEvent.datacontenttype) + && Objects.equals(data, repoEvent.data) + && Objects.equals(extensionAttributes, repoEvent.extensionAttributes); } @Override @@ -165,15 +165,15 @@ public String toString() { final StringBuilder sb = new StringBuilder(250); sb.append("RepoEvent [specversion=").append(specversion) - .append(", type=").append(type) - .append(", id=").append(id) - .append(", source=").append(source) - .append(", time=").append(time) - .append(", dataschema=").append(dataschema) - .append(", datacontenttype=").append(datacontenttype) - .append(", data=").append(data) - .append(", extensionAttributes=").append(extensionAttributes) - .append(']'); + .append(", type=").append(type) + .append(", id=").append(id) + .append(", source=").append(source) + .append(", time=").append(time) + .append(", dataschema=").append(dataschema) + .append(", datacontenttype=").append(datacontenttype) + .append(", data=").append(data) + .append(", extensionAttributes=").append(extensionAttributes) + .append(']'); return sb.toString(); } diff --git a/src/main/java/org/alfresco/repo/event/v1/model/Resource.java b/src/main/java/org/alfresco/repo/event/v1/model/Resource.java index 509246d..f180749 100644 --- a/src/main/java/org/alfresco/repo/event/v1/model/Resource.java +++ b/src/main/java/org/alfresco/repo/event/v1/model/Resource.java @@ -31,5 +31,4 @@ * @author Jamal Kaabi-Mofrad */ public interface Resource -{ -} +{} diff --git a/src/main/java/org/alfresco/repo/event/v1/model/UserInfo.java b/src/main/java/org/alfresco/repo/event/v1/model/UserInfo.java index 8f0871d..e0f3dff 100644 --- a/src/main/java/org/alfresco/repo/event/v1/model/UserInfo.java +++ b/src/main/java/org/alfresco/repo/event/v1/model/UserInfo.java @@ -36,8 +36,7 @@ public class UserInfo private String displayName; public UserInfo() - { - } + {} public UserInfo(String id, String firstName, String lastName) { @@ -68,7 +67,7 @@ public boolean equals(Object o) } UserInfo userInfo = (UserInfo) o; return Objects.equals(id, userInfo.id) - && Objects.equals(displayName, userInfo.displayName); + && Objects.equals(displayName, userInfo.displayName); } @Override @@ -82,8 +81,8 @@ public String toString() { final StringBuilder sb = new StringBuilder(100); sb.append("UserInfo [id=").append(id) - .append(", displayName=").append(displayName) - .append(']'); + .append(", displayName=").append(displayName) + .append(']'); return sb.toString(); } diff --git a/src/test/java/org/alfresco/repo/event/util/NodeResourceUtilsTest.java b/src/test/java/org/alfresco/repo/event/util/NodeResourceUtilsTest.java index 5c73026..eb7503c 100644 --- a/src/test/java/org/alfresco/repo/event/util/NodeResourceUtilsTest.java +++ b/src/test/java/org/alfresco/repo/event/util/NodeResourceUtilsTest.java @@ -26,10 +26,16 @@ package org.alfresco.repo.event.util; -import org.alfresco.repo.event.v1.model.ContentInfo; -import org.alfresco.repo.event.v1.model.NodeResource; -import org.alfresco.repo.event.v1.model.UserInfo; -import org.junit.Test; +import static java.util.Locale.ENGLISH; +import static java.util.Locale.GERMAN; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; + +import static org.alfresco.repo.event.util.TestUtil.getSecondaryParents; +import static org.alfresco.repo.event.util.TestUtil.getTestNodePrimaryHierarchy; +import static org.alfresco.repo.event.util.TestUtil.getUUID; import java.lang.reflect.Field; import java.time.ZonedDateTime; @@ -37,60 +43,56 @@ import java.util.Map; import java.util.Set; -import static java.util.Locale.ENGLISH; -import static java.util.Locale.GERMAN; +import org.junit.jupiter.api.Test; -import static org.alfresco.repo.event.util.TestUtil.getSecondaryParents; -import static org.alfresco.repo.event.util.TestUtil.getTestNodePrimaryHierarchy; -import static org.alfresco.repo.event.util.TestUtil.getUUID; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import org.alfresco.repo.event.v1.model.ContentInfo; +import org.alfresco.repo.event.v1.model.NodeResource; +import org.alfresco.repo.event.v1.model.UserInfo; public class NodeResourceUtilsTest { - @Test - public void nodeResource_createCopyFromBuilder() - { - // GIVEN: a nodeResource with all fields setup - NodeResource originalResource = NodeResource.builder() - .setId(getUUID()) - .setName("testFile.txt") - .setPrimaryHierarchy(getTestNodePrimaryHierarchy()) - .setIsFile(true) - .setIsFolder(false) - .setNodeType("cm:content") - .setPrimaryAssocQName("cm:testFile.txt") - .setCreatedByUser(new UserInfo("john.doe", "John", "Doe")) - .setCreatedAt(ZonedDateTime.now()) - .setModifiedByUser(new UserInfo("jane.doe", "Jane", "Doe")) - .setModifiedAt(ZonedDateTime.now()) - .setProperties(Map.of("cm:title", "test title", "cm:from", new Date(-2637887000L))) - .setLocalizedProperties(Map.of("cm:description", - Map.of(GERMAN.getLanguage(), "ruf mich an", ENGLISH.getLanguage(), "call me"))) - .setAspectNames(Set.of("cm:titled", "cm:auditable")) - .setContent(new ContentInfo("text/plain", 16L, "UTF-8")) - .setSecondaryParents(getSecondaryParents()) - .build(); + @Test + public void nodeResource_createCopyFromBuilder() + { + // GIVEN: a nodeResource with all fields setup + NodeResource originalResource = NodeResource.builder() + .setId(getUUID()) + .setName("testFile.txt") + .setPrimaryHierarchy(getTestNodePrimaryHierarchy()) + .setIsFile(true) + .setIsFolder(false) + .setNodeType("cm:content") + .setPrimaryAssocQName("cm:testFile.txt") + .setCreatedByUser(new UserInfo("john.doe", "John", "Doe")) + .setCreatedAt(ZonedDateTime.now()) + .setModifiedByUser(new UserInfo("jane.doe", "Jane", "Doe")) + .setModifiedAt(ZonedDateTime.now()) + .setProperties(Map.of("cm:title", "test title", "cm:from", new Date(-2637887000L))) + .setLocalizedProperties(Map.of("cm:description", + Map.of(GERMAN.getLanguage(), "ruf mich an", ENGLISH.getLanguage(), "call me"))) + .setAspectNames(Set.of("cm:titled", "cm:auditable")) + .setContent(new ContentInfo("text/plain", 16L, "UTF-8")) + .setSecondaryParents(getSecondaryParents()) + .build(); - // asserts that all fields have information (are non-null) - try - { - for (Field field : NodeResource.class.getDeclaredFields()) - { - field.setAccessible(true); - assertNotNull(field.get(originalResource)); - } - } - catch( IllegalAccessException exception ) - { - fail("all fields should be accessible in this test"); - } + // asserts that all fields have information (are non-null) + try + { + for (Field field : NodeResource.class.getDeclaredFields()) + { + field.setAccessible(true); + assertNotNull(field.get(originalResource)); + } + } + catch (IllegalAccessException exception) + { + fail("all fields should be accessible in this test"); + } - // WHEN: a new nodeResource is created based on the original nodeResource - final NodeResource copiedResource = NodeResourceUtils.getFilledBuilder(originalResource).build(); + // WHEN: a new nodeResource is created based on the original nodeResource + final NodeResource copiedResource = NodeResourceUtils.getFilledBuilder(originalResource).build(); - // THEN: the new nodeResource must have the same information as the original one - assertEquals(originalResource, copiedResource); - } + // THEN: the new nodeResource must have the same information as the original one + assertEquals(originalResource, copiedResource); + } } diff --git a/src/test/java/org/alfresco/repo/event/util/TestUtil.java b/src/test/java/org/alfresco/repo/event/util/TestUtil.java index 3ba4545..38ac387 100644 --- a/src/test/java/org/alfresco/repo/event/util/TestUtil.java +++ b/src/test/java/org/alfresco/repo/event/util/TestUtil.java @@ -37,7 +37,7 @@ import java.util.UUID; import java.util.regex.Pattern; -import org.alfresco.repo.event.databind.ObjectMapperFactory; +import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.io.IOUtils; import org.json.JSONException; import org.skyscreamer.jsonassert.Customization; @@ -46,7 +46,7 @@ import org.skyscreamer.jsonassert.ValueMatcher; import org.skyscreamer.jsonassert.comparator.CustomComparator; -import com.fasterxml.jackson.databind.ObjectMapper; +import org.alfresco.repo.event.databind.ObjectMapperFactory; /** * @author Jamal Kaabi-Mofrad @@ -56,9 +56,9 @@ public class TestUtil public static final ObjectMapper OBJECT_MAPPER = ObjectMapperFactory.createInstance(); public static final Pattern UUID_PATTERN = Pattern.compile( - "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}"); + "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}"); public static final Pattern DATE_TIME_PATTERN = Pattern.compile( - "^([0-9]+)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])[Tt]([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\\.[0-9]+)?(([Zz])|([+|\\-]([01][0-9]|2[0-3]):[0-5][0-9]))$"); + "^([0-9]+)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])[Tt]([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\\.[0-9]+)?(([Zz])|([+|\\-]([01][0-9]|2[0-3]):[0-5][0-9]))$"); public static final ValueMatcher UUID_VALUE_MATCHER = (o1, o2) -> { // Just check that the "actual" value (o1) and expected value (o2) @@ -85,30 +85,29 @@ public class TestUtil } }; - public static final Customization[] CUSTOMIZATIONS = new Customization[] { - new Customization("id", UUID_VALUE_MATCHER), - new Customization("data.eventGroupId", UUID_VALUE_MATCHER), - new Customization("data.resource.id", UUID_VALUE_MATCHER), - new Customization("data.resource.parent.id", UUID_VALUE_MATCHER), - new Customization("data.resource.child.id", UUID_VALUE_MATCHER), - new Customization("data.resource.source.id", UUID_VALUE_MATCHER), - new Customization("data.resource.target.id", UUID_VALUE_MATCHER), - new Customization("time", DATE_TIME_VALUE_MATCHER), - new Customization("data.resource.createdAt", DATE_TIME_VALUE_MATCHER), - new Customization("data.resource.modifiedAt", DATE_TIME_VALUE_MATCHER), - new Customization("data.resourceBefore.modifiedAt", DATE_TIME_VALUE_MATCHER), - new Customization("data.resource.aspectNames", ELEMENTS_ORDERING_MATCHER), - new Customization("extensionAttributes.extObject.id", UUID_VALUE_MATCHER), - new Customization("extensionAttributes.extObject.setProp", ELEMENTS_ORDERING_MATCHER), - new Customization("extensionAttributes.extObject.mapProp", ELEMENTS_ORDERING_MATCHER), - new Customization("data.resourceReaderAuthorities", TestUtil.ELEMENTS_ORDERING_MATCHER), - new Customization("data.resourceDeniedAuthorities", TestUtil.ELEMENTS_ORDERING_MATCHER), - new Customization("data.resourceReaderSecurityControls", TestUtil.ELEMENTS_ORDERING_MATCHER), - new Customization("extensionAttributes.client.id", TestUtil.UUID_VALUE_MATCHER),}; + public static final Customization[] CUSTOMIZATIONS = new Customization[]{ + new Customization("id", UUID_VALUE_MATCHER), + new Customization("data.eventGroupId", UUID_VALUE_MATCHER), + new Customization("data.resource.id", UUID_VALUE_MATCHER), + new Customization("data.resource.parent.id", UUID_VALUE_MATCHER), + new Customization("data.resource.child.id", UUID_VALUE_MATCHER), + new Customization("data.resource.source.id", UUID_VALUE_MATCHER), + new Customization("data.resource.target.id", UUID_VALUE_MATCHER), + new Customization("time", DATE_TIME_VALUE_MATCHER), + new Customization("data.resource.createdAt", DATE_TIME_VALUE_MATCHER), + new Customization("data.resource.modifiedAt", DATE_TIME_VALUE_MATCHER), + new Customization("data.resourceBefore.modifiedAt", DATE_TIME_VALUE_MATCHER), + new Customization("data.resource.aspectNames", ELEMENTS_ORDERING_MATCHER), + new Customization("extensionAttributes.extObject.id", UUID_VALUE_MATCHER), + new Customization("extensionAttributes.extObject.setProp", ELEMENTS_ORDERING_MATCHER), + new Customization("extensionAttributes.extObject.mapProp", ELEMENTS_ORDERING_MATCHER), + new Customization("data.resourceReaderAuthorities", TestUtil.ELEMENTS_ORDERING_MATCHER), + new Customization("data.resourceDeniedAuthorities", TestUtil.ELEMENTS_ORDERING_MATCHER), + new Customization("data.resourceReaderSecurityControls", TestUtil.ELEMENTS_ORDERING_MATCHER), + new Customization("extensionAttributes.client.id", TestUtil.UUID_VALUE_MATCHER),}; public static final CustomComparator JSON_COMPARATOR = new CustomComparator(JSONCompareMode.STRICT, CUSTOMIZATIONS); - public static String getResourceFileAsString(String fileName) throws Exception { InputStream inputStream = TestUtil.class.getClassLoader().getResourceAsStream(fileName); diff --git a/src/test/java/org/alfresco/repo/event/v1/model/EventTest.java b/src/test/java/org/alfresco/repo/event/v1/model/EventTest.java index 0bb0bcd..4714d98 100644 --- a/src/test/java/org/alfresco/repo/event/v1/model/EventTest.java +++ b/src/test/java/org/alfresco/repo/event/v1/model/EventTest.java @@ -28,6 +28,9 @@ import static java.util.Locale.ENGLISH; import static java.util.Locale.GERMAN; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + import static org.alfresco.repo.event.util.TestUtil.OBJECT_MAPPER; import static org.alfresco.repo.event.util.TestUtil.checkExpectedJsonBody; import static org.alfresco.repo.event.util.TestUtil.getDataSchema; @@ -36,8 +39,6 @@ import static org.alfresco.repo.event.util.TestUtil.getTestNodePrimaryHierarchy; import static org.alfresco.repo.event.util.TestUtil.getUUID; import static org.alfresco.repo.event.util.TestUtil.parseTime; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; import java.time.ZonedDateTime; import java.util.Date; @@ -45,9 +46,9 @@ import java.util.Set; import com.fasterxml.jackson.core.type.TypeReference; +import org.junit.jupiter.api.Test; import org.alfresco.repo.event.util.TestUtil; -import org.junit.Test; /** * @author Jamal Kaabi-Mofrad @@ -58,37 +59,37 @@ public class EventTest public void nodeCreatedEvent_marshalling() throws Exception { NodeResource resource = NodeResource.builder() - .setId(getUUID()) - .setName("testFile.txt") - .setPrimaryHierarchy(getTestNodePrimaryHierarchy()) - .setIsFile(true) - .setIsFolder(false) - .setNodeType("cm:content") - .setPrimaryAssocQName("cm:testFile.txt") - .setCreatedByUser(new UserInfo("john.doe", "John", "Doe")) - .setCreatedAt(ZonedDateTime.now()) - .setModifiedByUser(new UserInfo("jane.doe", "Jane", "Doe")) - .setModifiedAt(ZonedDateTime.now()) - .setProperties(Map.of("cm:title", "test title", "cm:from", new Date(-2637887000L))) - .setLocalizedProperties(Map.of("cm:description", - Map.of(GERMAN.getLanguage(), "ruf mich an", ENGLISH.getLanguage(), "call me"))) - .setAspectNames(Set.of("cm:titled", "cm:auditable")) - .setContent(new ContentInfo("text/plain", 16L, "UTF-8")) - .setSecondaryParents(getSecondaryParents()) - .build(); - - EventData eventData = EventData.builder() - .setEventGroupId(getUUID()) - .setResource(resource) - .build(); - - RepoEvent> repoEvent = RepoEvent.>builder().setId(getUUID()) - .setSource(getSource()) - .setTime(ZonedDateTime.now()) - .setType(EventType.NODE_CREATED.getType()) - .setData(eventData) - .setDataschema(getDataSchema("nodeCreated")) - .build(); + .setId(getUUID()) + .setName("testFile.txt") + .setPrimaryHierarchy(getTestNodePrimaryHierarchy()) + .setIsFile(true) + .setIsFolder(false) + .setNodeType("cm:content") + .setPrimaryAssocQName("cm:testFile.txt") + .setCreatedByUser(new UserInfo("john.doe", "John", "Doe")) + .setCreatedAt(ZonedDateTime.now()) + .setModifiedByUser(new UserInfo("jane.doe", "Jane", "Doe")) + .setModifiedAt(ZonedDateTime.now()) + .setProperties(Map.of("cm:title", "test title", "cm:from", new Date(-2637887000L))) + .setLocalizedProperties(Map.of("cm:description", + Map.of(GERMAN.getLanguage(), "ruf mich an", ENGLISH.getLanguage(), "call me"))) + .setAspectNames(Set.of("cm:titled", "cm:auditable")) + .setContent(new ContentInfo("text/plain", 16L, "UTF-8")) + .setSecondaryParents(getSecondaryParents()) + .build(); + + EventData eventData = EventData. builder() + .setEventGroupId(getUUID()) + .setResource(resource) + .build(); + + RepoEvent> repoEvent = RepoEvent.> builder().setId(getUUID()) + .setSource(getSource()) + .setTime(ZonedDateTime.now()) + .setType(EventType.NODE_CREATED.getType()) + .setData(eventData) + .setDataschema(getDataSchema("nodeCreated")) + .build(); String result = OBJECT_MAPPER.writeValueAsString(repoEvent); String expectedJson = TestUtil.getResourceFileAsString("noAuth/NodeCreatedEvent.json"); @@ -101,42 +102,40 @@ public void nodeCreatedEvent_unmarshalling() throws Exception { String nodeCreatedEventJson = TestUtil.getResourceFileAsString("noAuth/NodeCreatedEvent.json"); assertNotNull(nodeCreatedEventJson); - RepoEvent> result = OBJECT_MAPPER.readValue(nodeCreatedEventJson, new TypeReference<>() - { - }); + RepoEvent> result = OBJECT_MAPPER.readValue(nodeCreatedEventJson, new TypeReference<>() {}); NodeResource resource = NodeResource.builder() - .setId("7491120a-e2cb-478f-8599-ebf057cc0c7c") - .setName("testFile.txt") - .setPrimaryHierarchy(getTestNodePrimaryHierarchy()) - .setIsFile(true) - .setIsFolder(false) - .setNodeType("cm:content") - .setPrimaryAssocQName("cm:testFile.txt") - .setCreatedByUser(new UserInfo("john.doe", "John", "Doe")) - .setCreatedAt(parseTime("2020-04-27T12:37:03.555624+01:00")) - .setModifiedByUser(new UserInfo("jane.doe", "Jane", "Doe")) - .setModifiedAt(parseTime("2020-04-27T12:37:03.557956+01:00")) - .setProperties(Map.of("cm:title", "test title", "cm:from", "1969-12-01T11:15:13Z")) - .setLocalizedProperties(Map.of("cm:description", - Map.of(GERMAN.getLanguage(), "ruf mich an", ENGLISH.getLanguage(), "call me"))) - .setAspectNames(Set.of("cm:titled", "cm:auditable")) - .setContent(new ContentInfo("text/plain", 16L, "UTF-8")) - .setSecondaryParents(getSecondaryParents()) - .build(); - - EventData eventData = EventData.builder().setEventGroupId( - "cb645043-e7d2-4e51-b61d-e6d01582cbab") - .setResource(resource).build(); - - RepoEvent> repoEvent = RepoEvent.>builder().setId( - "97c1b36c-c569-4c66-8a31-7a8d0b6b804a") - .setSource(getSource()) - .setTime(parseTime("2020-04-27T12:37:03.560134+01:00")) - .setType(EventType.NODE_CREATED.getType()) - .setData(eventData) - .setDataschema(getDataSchema("nodeCreated")) - .build(); + .setId("7491120a-e2cb-478f-8599-ebf057cc0c7c") + .setName("testFile.txt") + .setPrimaryHierarchy(getTestNodePrimaryHierarchy()) + .setIsFile(true) + .setIsFolder(false) + .setNodeType("cm:content") + .setPrimaryAssocQName("cm:testFile.txt") + .setCreatedByUser(new UserInfo("john.doe", "John", "Doe")) + .setCreatedAt(parseTime("2020-04-27T12:37:03.555624+01:00")) + .setModifiedByUser(new UserInfo("jane.doe", "Jane", "Doe")) + .setModifiedAt(parseTime("2020-04-27T12:37:03.557956+01:00")) + .setProperties(Map.of("cm:title", "test title", "cm:from", "1969-12-01T11:15:13Z")) + .setLocalizedProperties(Map.of("cm:description", + Map.of(GERMAN.getLanguage(), "ruf mich an", ENGLISH.getLanguage(), "call me"))) + .setAspectNames(Set.of("cm:titled", "cm:auditable")) + .setContent(new ContentInfo("text/plain", 16L, "UTF-8")) + .setSecondaryParents(getSecondaryParents()) + .build(); + + EventData eventData = EventData. builder().setEventGroupId( + "cb645043-e7d2-4e51-b61d-e6d01582cbab") + .setResource(resource).build(); + + RepoEvent> repoEvent = RepoEvent.> builder().setId( + "97c1b36c-c569-4c66-8a31-7a8d0b6b804a") + .setSource(getSource()) + .setTime(parseTime("2020-04-27T12:37:03.560134+01:00")) + .setType(EventType.NODE_CREATED.getType()) + .setData(eventData) + .setDataschema(getDataSchema("nodeCreated")) + .build(); assertEquals(repoEvent, result); } @@ -145,45 +144,45 @@ public void nodeCreatedEvent_unmarshalling() throws Exception public void nodeUpdatedEvent_marshalling() throws Exception { NodeResource resource = NodeResource.builder() - .setId(getUUID()) - .setName("testFile.txt") - .setPrimaryHierarchy(getTestNodePrimaryHierarchy()) - .setIsFile(true) - .setIsFolder(false) - .setNodeType("cm:content") - .setPrimaryAssocQName("cm:testFile.txt") - .setCreatedByUser(new UserInfo("john.doe", "John", "Doe")) - .setCreatedAt(ZonedDateTime.now()) - .setModifiedByUser(new UserInfo("jane.doe", "Jane", "Doe")) - .setModifiedAt(ZonedDateTime.now()) - .setProperties(Map.of("cm:title", "test title2", "cm:description", "test description.")) - .setLocalizedProperties(Map.of("cm:description", - Map.of(GERMAN.getLanguage(), "ruf mich an", ENGLISH.getLanguage(), "call me"))) - .setAspectNames(Set.of("cm:titled", "cm:auditable")) - .setContent(new ContentInfo("text/plain", 16L, "UTF-8")) - .setSecondaryParents(getSecondaryParents()) - .build(); + .setId(getUUID()) + .setName("testFile.txt") + .setPrimaryHierarchy(getTestNodePrimaryHierarchy()) + .setIsFile(true) + .setIsFolder(false) + .setNodeType("cm:content") + .setPrimaryAssocQName("cm:testFile.txt") + .setCreatedByUser(new UserInfo("john.doe", "John", "Doe")) + .setCreatedAt(ZonedDateTime.now()) + .setModifiedByUser(new UserInfo("jane.doe", "Jane", "Doe")) + .setModifiedAt(ZonedDateTime.now()) + .setProperties(Map.of("cm:title", "test title2", "cm:description", "test description.")) + .setLocalizedProperties(Map.of("cm:description", + Map.of(GERMAN.getLanguage(), "ruf mich an", ENGLISH.getLanguage(), "call me"))) + .setAspectNames(Set.of("cm:titled", "cm:auditable")) + .setContent(new ContentInfo("text/plain", 16L, "UTF-8")) + .setSecondaryParents(getSecondaryParents()) + .build(); NodeResource resourceBefore = NodeResource.builder() - .setModifiedByUser(new UserInfo("jane.doe", "Jane", "Doe")) - .setModifiedAt(ZonedDateTime.now()) - .setProperties(Map.of("cm:title", "test title")) - .setLocalizedProperties(Map.of("cm:description", Map.of(GERMAN.getLanguage(), "ruf mi an"))) - .build(); - - EventData eventData = EventData.builder() - .setEventGroupId(getUUID()) - .setResource(resource) - .setResourceBefore(resourceBefore) - .build(); - - RepoEvent> repoEvent = RepoEvent.>builder().setId(getUUID()) - .setSource(getSource()) - .setTime(ZonedDateTime.now()) - .setType(EventType.NODE_UPDATED.getType()) - .setData(eventData) - .setDataschema(getDataSchema("nodeUpdated")) - .build(); + .setModifiedByUser(new UserInfo("jane.doe", "Jane", "Doe")) + .setModifiedAt(ZonedDateTime.now()) + .setProperties(Map.of("cm:title", "test title")) + .setLocalizedProperties(Map.of("cm:description", Map.of(GERMAN.getLanguage(), "ruf mi an"))) + .build(); + + EventData eventData = EventData. builder() + .setEventGroupId(getUUID()) + .setResource(resource) + .setResourceBefore(resourceBefore) + .build(); + + RepoEvent> repoEvent = RepoEvent.> builder().setId(getUUID()) + .setSource(getSource()) + .setTime(ZonedDateTime.now()) + .setType(EventType.NODE_UPDATED.getType()) + .setData(eventData) + .setDataschema(getDataSchema("nodeUpdated")) + .build(); String result = OBJECT_MAPPER.writeValueAsString(repoEvent); String expectedJson = TestUtil.getResourceFileAsString("noAuth/NodeUpdatedEvent.json"); @@ -196,51 +195,49 @@ public void nodeUpdatedEvent_unmarshalling() throws Exception { String nodeUpdatedEventJson = TestUtil.getResourceFileAsString("noAuth/NodeUpdatedEvent.json"); assertNotNull(nodeUpdatedEventJson); - RepoEvent> result = OBJECT_MAPPER.readValue(nodeUpdatedEventJson, new TypeReference<>() - { - }); + RepoEvent> result = OBJECT_MAPPER.readValue(nodeUpdatedEventJson, new TypeReference<>() {}); NodeResource expectedResource = NodeResource.builder() - .setId("d366f805-853f-46ac-a81c-af9c257ee876") - .setName("testFile.txt") - .setPrimaryHierarchy(getTestNodePrimaryHierarchy()) - .setIsFile(true) - .setIsFolder(false) - .setNodeType("cm:content") - .setPrimaryAssocQName("cm:testFile.txt") - .setCreatedByUser(new UserInfo("john.doe", "John", "Doe")) - .setCreatedAt(parseTime("2020-04-27T14:25:59.852475+01:00")) - .setModifiedByUser(new UserInfo("jane.doe", "Jane", "Doe")) - .setModifiedAt(parseTime("2020-04-27T14:25:59.854153+01:00")) - .setProperties(Map.of("cm:title", "test title2", "cm:description", "test description.")) - .setLocalizedProperties(Map.of("cm:description", - Map.of(GERMAN.getLanguage(), "ruf mich an", ENGLISH.getLanguage(), "call me"))) - .setAspectNames(Set.of("cm:titled", "cm:auditable")) - .setContent(new ContentInfo("text/plain", 16L, "UTF-8")) - .setSecondaryParents(getSecondaryParents()) - .build(); + .setId("d366f805-853f-46ac-a81c-af9c257ee876") + .setName("testFile.txt") + .setPrimaryHierarchy(getTestNodePrimaryHierarchy()) + .setIsFile(true) + .setIsFolder(false) + .setNodeType("cm:content") + .setPrimaryAssocQName("cm:testFile.txt") + .setCreatedByUser(new UserInfo("john.doe", "John", "Doe")) + .setCreatedAt(parseTime("2020-04-27T14:25:59.852475+01:00")) + .setModifiedByUser(new UserInfo("jane.doe", "Jane", "Doe")) + .setModifiedAt(parseTime("2020-04-27T14:25:59.854153+01:00")) + .setProperties(Map.of("cm:title", "test title2", "cm:description", "test description.")) + .setLocalizedProperties(Map.of("cm:description", + Map.of(GERMAN.getLanguage(), "ruf mich an", ENGLISH.getLanguage(), "call me"))) + .setAspectNames(Set.of("cm:titled", "cm:auditable")) + .setContent(new ContentInfo("text/plain", 16L, "UTF-8")) + .setSecondaryParents(getSecondaryParents()) + .build(); NodeResource expectedResourceBefore = NodeResource.builder() - .setModifiedByUser(new UserInfo("jane.doe", "Jane", "Doe")) - .setModifiedAt(parseTime("2020-04-27T14:25:59.854558+01:00")) - .setProperties(Map.of("cm:title", "test title")) - .setLocalizedProperties(Map.of("cm:description", Map.of(GERMAN.getLanguage(), "ruf mi an"))) - .build(); - - EventData expectedEventData = EventData.builder() - .setEventGroupId("ce852a52-609e-4b7d-8438-04e211fd76a0") - .setResource(expectedResource) - .setResourceBefore(expectedResourceBefore) - .build(); - - RepoEvent> expectedRepoEvent = RepoEvent.>builder().setId( - "df708027-e0a8-4b30-92a5-0d19235a7800") - .setSource(getSource()) - .setTime(parseTime("2020-04-27T14:25:59.855866+01:00")) - .setType(EventType.NODE_UPDATED.getType()) - .setData(expectedEventData) - .setDataschema(getDataSchema("nodeUpdated")) - .build(); + .setModifiedByUser(new UserInfo("jane.doe", "Jane", "Doe")) + .setModifiedAt(parseTime("2020-04-27T14:25:59.854558+01:00")) + .setProperties(Map.of("cm:title", "test title")) + .setLocalizedProperties(Map.of("cm:description", Map.of(GERMAN.getLanguage(), "ruf mi an"))) + .build(); + + EventData expectedEventData = EventData. builder() + .setEventGroupId("ce852a52-609e-4b7d-8438-04e211fd76a0") + .setResource(expectedResource) + .setResourceBefore(expectedResourceBefore) + .build(); + + RepoEvent> expectedRepoEvent = RepoEvent.> builder().setId( + "df708027-e0a8-4b30-92a5-0d19235a7800") + .setSource(getSource()) + .setTime(parseTime("2020-04-27T14:25:59.855866+01:00")) + .setType(EventType.NODE_UPDATED.getType()) + .setData(expectedEventData) + .setDataschema(getDataSchema("nodeUpdated")) + .build(); assertEquals(expectedRepoEvent, result); } @@ -248,24 +245,24 @@ public void nodeUpdatedEvent_unmarshalling() throws Exception @Test public void childAssocCreatedEvent_marshalling() throws Exception { - ChildAssociationResource childAssocResource = new ChildAssociationResource(getUUID(), - getUUID(), - "cm:contains", - "cm:213131-1234-1235-5432-12039400a121"); - - EventData eventData = EventData.builder() - .setEventGroupId(getUUID()) - .setResource(childAssocResource) - .build(); - - RepoEvent> repoEvent = RepoEvent.>builder() - .setId(getUUID()) - .setSource(getSource()) - .setTime(ZonedDateTime.now()) - .setType(EventType.CHILD_ASSOC_CREATED.getType()) - .setData(eventData) - .setDataschema(getDataSchema("childAssocCreated")) - .build(); + ChildAssociationResource childAssocResource = new ChildAssociationResource(getUUID(), + getUUID(), + "cm:contains", + "cm:213131-1234-1235-5432-12039400a121"); + + EventData eventData = EventData. builder() + .setEventGroupId(getUUID()) + .setResource(childAssocResource) + .build(); + + RepoEvent> repoEvent = RepoEvent.> builder() + .setId(getUUID()) + .setSource(getSource()) + .setTime(ZonedDateTime.now()) + .setType(EventType.CHILD_ASSOC_CREATED.getType()) + .setData(eventData) + .setDataschema(getDataSchema("childAssocCreated")) + .build(); String result = OBJECT_MAPPER.writeValueAsString(repoEvent); String expectedJson = TestUtil.getResourceFileAsString("noAuth/ChildAssocCreated.json"); @@ -278,28 +275,26 @@ public void childAssocCreatedEvent_unmarshalling() throws Exception { String childAssocCreatedEventJson = TestUtil.getResourceFileAsString("noAuth/ChildAssocCreated.json"); assertNotNull(childAssocCreatedEventJson); - RepoEvent> result = OBJECT_MAPPER.readValue(childAssocCreatedEventJson, new TypeReference<>() - { - }); + RepoEvent> result = OBJECT_MAPPER.readValue(childAssocCreatedEventJson, new TypeReference<>() {}); ChildAssociationResource expectedResource = new ChildAssociationResource("7624edb6-6f28-4130-a4fb-4a5362807a05", - "5d9f3d6f-9802-4bb6-8ad3-0f9261d08894", - "cm:contains", - "cm:213131-1234-1235-5432-12039400a121"); - - EventData expectedEventData = EventData.builder() - .setEventGroupId("d933857e-5f4f-406e-aa5f-c747901f5a8f") - .setResource(expectedResource) - .build(); - - RepoEvent> expectedRepoEvent = RepoEvent.>builder() - .setId("928c28fc-da23-441d-bb8b-72b068a9ceb5") - .setSource(getSource()) - .setTime(parseTime("2020-05-28T09:56:52.235411+01:00")) - .setType(EventType.CHILD_ASSOC_CREATED.getType()) - .setData(expectedEventData) - .setDataschema(getDataSchema("childAssocCreated")) - .build(); + "5d9f3d6f-9802-4bb6-8ad3-0f9261d08894", + "cm:contains", + "cm:213131-1234-1235-5432-12039400a121"); + + EventData expectedEventData = EventData. builder() + .setEventGroupId("d933857e-5f4f-406e-aa5f-c747901f5a8f") + .setResource(expectedResource) + .build(); + + RepoEvent> expectedRepoEvent = RepoEvent.> builder() + .setId("928c28fc-da23-441d-bb8b-72b068a9ceb5") + .setSource(getSource()) + .setTime(parseTime("2020-05-28T09:56:52.235411+01:00")) + .setType(EventType.CHILD_ASSOC_CREATED.getType()) + .setData(expectedEventData) + .setDataschema(getDataSchema("childAssocCreated")) + .build(); assertEquals(expectedRepoEvent, result); } @@ -309,19 +304,19 @@ public void peerAssocCreatedEvent_marshalling() throws Exception { PeerAssociationResource peerAssocResource = new PeerAssociationResource(getUUID(), getUUID(), "cm:references"); - EventData eventData = EventData.builder() - .setEventGroupId(getUUID()) - .setResource(peerAssocResource) - .build(); + EventData eventData = EventData. builder() + .setEventGroupId(getUUID()) + .setResource(peerAssocResource) + .build(); - RepoEvent> repoEvent = RepoEvent.>builder() - .setId(getUUID()) - .setSource(getSource()) - .setTime(ZonedDateTime.now()) - .setType(EventType.PEER_ASSOC_CREATED.getType()) - .setData(eventData) - .setDataschema(getDataSchema("peerAssocCreated")) - .build(); + RepoEvent> repoEvent = RepoEvent.> builder() + .setId(getUUID()) + .setSource(getSource()) + .setTime(ZonedDateTime.now()) + .setType(EventType.PEER_ASSOC_CREATED.getType()) + .setData(eventData) + .setDataschema(getDataSchema("peerAssocCreated")) + .build(); String result = OBJECT_MAPPER.writeValueAsString(repoEvent); String expectedJson = TestUtil.getResourceFileAsString("noAuth/PeerAssocCreated.json"); @@ -334,27 +329,25 @@ public void peerAssocCreatedEvent_unmarshalling() throws Exception { String peerAssocCreatedEventJson = TestUtil.getResourceFileAsString("noAuth/PeerAssocCreated.json"); assertNotNull(peerAssocCreatedEventJson); - RepoEvent> result = OBJECT_MAPPER.readValue(peerAssocCreatedEventJson, new TypeReference<>() - { - }); + RepoEvent> result = OBJECT_MAPPER.readValue(peerAssocCreatedEventJson, new TypeReference<>() {}); PeerAssociationResource expectedResource = new PeerAssociationResource("d323671c-9bd0-483e-8471-bd64cea73c09", - "595c55b0-64b3-4f1b-95f8-c1cc6b3843a2", - "cm:references"); - - EventData expectedEventData = EventData.builder() - .setEventGroupId("b23f75d0-45da-40d1-9063-eb800a4f2444") - .setResource(expectedResource) - .build(); - - RepoEvent> expectedRepoEvent = RepoEvent.>builder() - .setId("8677a369-a30d-469e-b313-e5bf1b590c8e") - .setSource(getSource()) - .setTime(parseTime("2020-05-28T10:36:21.291392+01:00")) - .setType(EventType.PEER_ASSOC_CREATED.getType()) - .setData(expectedEventData) - .setDataschema(getDataSchema("peerAssocCreated")) - .build(); + "595c55b0-64b3-4f1b-95f8-c1cc6b3843a2", + "cm:references"); + + EventData expectedEventData = EventData. builder() + .setEventGroupId("b23f75d0-45da-40d1-9063-eb800a4f2444") + .setResource(expectedResource) + .build(); + + RepoEvent> expectedRepoEvent = RepoEvent.> builder() + .setId("8677a369-a30d-469e-b313-e5bf1b590c8e") + .setSource(getSource()) + .setTime(parseTime("2020-05-28T10:36:21.291392+01:00")) + .setType(EventType.PEER_ASSOC_CREATED.getType()) + .setData(expectedEventData) + .setDataschema(getDataSchema("peerAssocCreated")) + .build(); assertEquals(expectedRepoEvent, result); } @@ -380,13 +373,13 @@ public void nodeCreatedWithAuthoritiesEvent_marshalling() throws Exception .setContent(new ContentInfo("text/plain", 16L, "UTF-8")) .build(); - EventData eventData = EventData.builder().setEventGroupId(getUUID()) + EventData eventData = EventData. builder().setEventGroupId(getUUID()) .setResource(resource) .setResourceReaderAuthorities(Set.of("GROUP_EVERYONE", "GROUP_ONE", "GROUP_TWO")) .setResourceDeniedAuthorities(Set.of()) .build(); - RepoEvent> repoEvent = RepoEvent.>builder().setId(getUUID()) + RepoEvent> repoEvent = RepoEvent.> builder().setId(getUUID()) .setSource(getSource()) .setTime(ZonedDateTime.now()) .setType("org.alfresco.event.node.Created") @@ -405,9 +398,7 @@ public void nodeCreatedWithAuthoritiesEvent_unmarshalling() throws Exception { String nodeCreatedEventJson = TestUtil.getResourceFileAsString("auth/NodeCreatedEvent.json"); assertNotNull(nodeCreatedEventJson); - RepoEvent> result = OBJECT_MAPPER.readValue(nodeCreatedEventJson, new TypeReference<>() - { - }); + RepoEvent> result = OBJECT_MAPPER.readValue(nodeCreatedEventJson, new TypeReference<>() {}); NodeResource resource = NodeResource.builder() .setId("7491120a-e2cb-478f-8599-ebf057cc0c7c") @@ -425,13 +416,13 @@ public void nodeCreatedWithAuthoritiesEvent_unmarshalling() throws Exception .setContent(new ContentInfo("text/plain", 16L, "UTF-8")) .build(); - EventData eventData = EventData.builder().setEventGroupId("cb645043-e7d2-4e51-b61d-e6d01582cbab") + EventData eventData = EventData. builder().setEventGroupId("cb645043-e7d2-4e51-b61d-e6d01582cbab") .setResource(resource) .setResourceReaderAuthorities(Set.of("GROUP_EVERYONE", "GROUP_ONE", "GROUP_TWO")) .setResourceDeniedAuthorities(Set.of()) .build(); - RepoEvent> repoEvent = RepoEvent.>builder().setId("97c1b36c-c569-4c66-8a31-7a8d0b6b804a") + RepoEvent> repoEvent = RepoEvent.> builder().setId("97c1b36c-c569-4c66-8a31-7a8d0b6b804a") .setSource(getSource()) .setTime(parseTime("2020-06-10T12:37:03.560134+01:00")) .setType("org.alfresco.event.node.Created") @@ -468,7 +459,7 @@ public void nodeUpdatedWithAuthoritiesEvent_marshalling() throws Exception .setProperties(Map.of("cm:title", "test title")) .build(); - EventData eventData = EventData.builder() + EventData eventData = EventData. builder() .setEventGroupId(getUUID()) .setResource(resource) .setResourceBefore(resourceBefore) @@ -477,7 +468,7 @@ public void nodeUpdatedWithAuthoritiesEvent_marshalling() throws Exception .setResourceReaderSecurityControls(Set.of("e428663f-9171-42e2-b233-d8f2cd3f54f7:mF2foUuA")) .build(); - RepoEvent> repoEvent = RepoEvent.>builder().setId(getUUID()) + RepoEvent> repoEvent = RepoEvent.> builder().setId(getUUID()) .setSource(getSource()) .setTime(ZonedDateTime.now()) .setType("org.alfresco.event.node.Updated") @@ -496,9 +487,7 @@ public void nodeUpdatedWithAuthoritiesEvent_unmarshalling() throws Exception { String nodeUpdatedEventJson = TestUtil.getResourceFileAsString("auth/NodeUpdatedEvent.json"); assertNotNull(nodeUpdatedEventJson); - RepoEvent> result = OBJECT_MAPPER.readValue(nodeUpdatedEventJson, new TypeReference<>() - { - }); + RepoEvent> result = OBJECT_MAPPER.readValue(nodeUpdatedEventJson, new TypeReference<>() {}); NodeResource expectedResource = NodeResource.builder() .setId("d366f805-853f-46ac-a81c-af9c257ee876") @@ -522,7 +511,7 @@ public void nodeUpdatedWithAuthoritiesEvent_unmarshalling() throws Exception .setProperties(Map.of("cm:title", "test title")) .build(); - EventData expectedEventData = EventData.builder() + EventData expectedEventData = EventData. builder() .setEventGroupId("ce852a52-609e-4b7d-8438-04e211fd76a0") .setResource(expectedResource) .setResourceBefore(expectedResourceBefore) @@ -531,8 +520,8 @@ public void nodeUpdatedWithAuthoritiesEvent_unmarshalling() throws Exception .setResourceReaderSecurityControls(Set.of("e428663f-9171-42e2-b233-d8f2cd3f54f7:mF2foUuA")) .build(); - RepoEvent> expectedRepoEvent = RepoEvent.>builder().setId( - "df708027-e0a8-4b30-92a5-0d19235a7800") + RepoEvent> expectedRepoEvent = RepoEvent.> builder().setId( + "df708027-e0a8-4b30-92a5-0d19235a7800") .setSource(getSource()) .setTime(parseTime("2020-06-10T14:25:59.855866+01:00")) .setType("org.alfresco.event.node.Updated") @@ -548,14 +537,14 @@ public void childAssocCreatedWithAuthoritiesEvent_marshalling() throws Exception { ChildAssociationResource childAssocResource = new ChildAssociationResource(getUUID(), getUUID(), "cm:contains", "cm:213131-1234-1235-5432-12039400a121"); - EventData eventData = EventData.builder() + EventData eventData = EventData. builder() .setEventGroupId(getUUID()) .setResource(childAssocResource) .setResourceReaderAuthorities(Set.of("GROUP_EVERYONE", "GROUP_ONE")) .setResourceDeniedAuthorities(Set.of("GROUP_TWO")) .build(); - RepoEvent> repoEvent = RepoEvent.>builder() + RepoEvent> repoEvent = RepoEvent.> builder() .setId(getUUID()) .setSource(getSource()) .setTime(ZonedDateTime.now()) @@ -575,23 +564,21 @@ public void childAssocCreatedWithAuthoritiesEvent_unmarshalling() throws Excepti { String childAssocCreatedEventJson = TestUtil.getResourceFileAsString("auth/ChildAssocCreated.json"); assertNotNull(childAssocCreatedEventJson); - RepoEvent> result = OBJECT_MAPPER.readValue(childAssocCreatedEventJson, new TypeReference<>() - { - }); + RepoEvent> result = OBJECT_MAPPER.readValue(childAssocCreatedEventJson, new TypeReference<>() {}); ChildAssociationResource expectedResource = new ChildAssociationResource("7624edb6-6f28-4130-a4fb-4a5362807a05", "5d9f3d6f-9802-4bb6-8ad3-0f9261d08894", "cm:contains", "cm:213131-1234-1235-5432-12039400a121"); - EventData expectedEventData = EventData.builder() + EventData expectedEventData = EventData. builder() .setEventGroupId("d933857e-5f4f-406e-aa5f-c747901f5a8f") .setResource(expectedResource) .setResourceReaderAuthorities(Set.of("GROUP_EVERYONE", "GROUP_ONE")) .setResourceDeniedAuthorities(Set.of("GROUP_TWO")) .build(); - RepoEvent> expectedRepoEvent = RepoEvent.>builder() + RepoEvent> expectedRepoEvent = RepoEvent.> builder() .setId("928c28fc-da23-441d-bb8b-72b068a9ceb5") .setSource(getSource()) .setTime(parseTime("2020-06-10T09:56:52.235411+01:00")) @@ -608,14 +595,14 @@ public void peerAssocCreatedWithAuthoritiesEvent_marshalling() throws Exception { PeerAssociationResource peerAssocResource = new PeerAssociationResource(getUUID(), getUUID(), "cm:references"); - EventData eventData = EventData.builder() + EventData eventData = EventData. builder() .setEventGroupId(getUUID()) .setResource(peerAssocResource) .setResourceReaderAuthorities(Set.of()) .setResourceDeniedAuthorities(Set.of("GROUP_TWO")) .build(); - RepoEvent> repoEvent = RepoEvent.>builder() + RepoEvent> repoEvent = RepoEvent.> builder() .setId(getUUID()) .setSource(getSource()) .setTime(ZonedDateTime.now()) @@ -635,22 +622,20 @@ public void peerAssocCreatedWithAuthoritiesEvent_unmarshalling() throws Exceptio { String peerAssocCreatedEventJson = TestUtil.getResourceFileAsString("auth/PeerAssocCreated.json"); assertNotNull(peerAssocCreatedEventJson); - RepoEvent> result = OBJECT_MAPPER.readValue(peerAssocCreatedEventJson, new TypeReference<>() - { - }); + RepoEvent> result = OBJECT_MAPPER.readValue(peerAssocCreatedEventJson, new TypeReference<>() {}); PeerAssociationResource expectedResource = new PeerAssociationResource("d323671c-9bd0-483e-8471-bd64cea73c09", "595c55b0-64b3-4f1b-95f8-c1cc6b3843a2", "cm:references"); - EventData expectedEventData = EventData.builder() + EventData expectedEventData = EventData. builder() .setEventGroupId("b23f75d0-45da-40d1-9063-eb800a4f2444") .setResource(expectedResource) .setResourceReaderAuthorities(Set.of()) .setResourceDeniedAuthorities(Set.of("GROUP_TWO")) .build(); - RepoEvent> expectedRepoEvent = RepoEvent.>builder() + RepoEvent> expectedRepoEvent = RepoEvent.> builder() .setId("8677a369-a30d-469e-b313-e5bf1b590c8e") .setSource(getSource()) .setTime(parseTime("2020-06-10T10:36:21.291392+01:00")) diff --git a/src/test/java/org/alfresco/repo/event/v1/model/NodeResourceTest.java b/src/test/java/org/alfresco/repo/event/v1/model/NodeResourceTest.java index f67f176..b7ef38a 100644 --- a/src/test/java/org/alfresco/repo/event/v1/model/NodeResourceTest.java +++ b/src/test/java/org/alfresco/repo/event/v1/model/NodeResourceTest.java @@ -27,14 +27,13 @@ import static java.util.Collections.emptyList; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; -/** Unit tests for {@NodeResource}. */ +/** Unit tests for {@link NodeResource} . */ public class NodeResourceTest { @Test @@ -46,7 +45,7 @@ public void setSecondaryParents_populatedListShouldBeStored() nodeResourceBuilder.setSecondaryParents(secondaryParents); NodeResource nodeResource = nodeResourceBuilder.build(); - assertEquals("Unexpected secondary parents.", nodeResource.getSecondaryParents(), secondaryParents); + assertEquals(nodeResource.getSecondaryParents(), secondaryParents, "Unexpected secondary parents."); } @Test @@ -57,7 +56,7 @@ public void setSecondaryParents_emptyListShouldBePreserved() nodeResourceBuilder.setSecondaryParents(emptyList()); NodeResource nodeResource = nodeResourceBuilder.build(); - assertEquals("Expected empty list of secondary parents.", nodeResource.getSecondaryParents(), emptyList()); + assertEquals(nodeResource.getSecondaryParents(), emptyList(), "Expected empty list of secondary parents."); } @Test @@ -68,6 +67,6 @@ public void setSecondaryParents_nullListShouldBeStoredAsEmpty() nodeResourceBuilder.setSecondaryParents(null); NodeResource nodeResource = nodeResourceBuilder.build(); - assertEquals("Expected empty list of secondary parents.", nodeResource.getSecondaryParents(), emptyList()); + assertEquals(nodeResource.getSecondaryParents(), emptyList(), "Expected empty list of secondary parents."); } } diff --git a/src/test/java/org/alfresco/repo/event/v1/model/extension/EventExtensionTest.java b/src/test/java/org/alfresco/repo/event/v1/model/extension/EventExtensionTest.java index f398358..ea89933 100644 --- a/src/test/java/org/alfresco/repo/event/v1/model/extension/EventExtensionTest.java +++ b/src/test/java/org/alfresco/repo/event/v1/model/extension/EventExtensionTest.java @@ -25,6 +25,9 @@ */ package org.alfresco.repo.event.v1.model.extension; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + import static org.alfresco.repo.event.util.TestUtil.OBJECT_MAPPER; import static org.alfresco.repo.event.util.TestUtil.checkExpectedJsonBody; import static org.alfresco.repo.event.util.TestUtil.getDataSchema; @@ -32,8 +35,6 @@ import static org.alfresco.repo.event.util.TestUtil.getTestNodePrimaryHierarchy; import static org.alfresco.repo.event.util.TestUtil.getUUID; import static org.alfresco.repo.event.util.TestUtil.parseTime; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; import java.time.ZonedDateTime; import java.util.Date; @@ -42,6 +43,9 @@ import java.util.Objects; import java.util.Set; +import com.fasterxml.jackson.core.type.TypeReference; +import org.junit.jupiter.api.Test; + import org.alfresco.repo.event.extension.ExtensionAttributes; import org.alfresco.repo.event.extension.ExtensionAttributesImpl; import org.alfresco.repo.event.util.TestUtil; @@ -51,9 +55,6 @@ import org.alfresco.repo.event.v1.model.NodeResource; import org.alfresco.repo.event.v1.model.RepoEvent; import org.alfresco.repo.event.v1.model.UserInfo; -import org.junit.Test; - -import com.fasterxml.jackson.core.type.TypeReference; /** * @author Jamal Kaabi-Mofrad @@ -64,26 +65,26 @@ public class EventExtensionTest public void nodeCreatedEventWithExtensionAttributes_marshalling() throws Exception { NodeResource resource = NodeResource.builder() - .setId(getUUID()) - .setName("testFile.txt") - .setPrimaryHierarchy(getTestNodePrimaryHierarchy()) - .setIsFile(true) - .setIsFolder(false) - .setNodeType("cm:content") - .setPrimaryAssocQName("cm:testFile.txt") - .setCreatedByUser(new UserInfo("john.doe", "John", "Doe")) - .setCreatedAt(ZonedDateTime.now()) - .setModifiedByUser(new UserInfo("jane.doe", "Jane", "Doe")) - .setModifiedAt(ZonedDateTime.now()) - .setProperties(Map.of("cm:title", "test title", "cm:from", new Date(-2637887000L))) - .setAspectNames(Set.of("cm:titled", "cm:auditable")) - .setContent(new ContentInfo("text/plain", 16L, "UTF-8")) - .build(); - - EventData eventData = EventData.builder() - .setEventGroupId(getUUID()) - .setResource(resource) - .build(); + .setId(getUUID()) + .setName("testFile.txt") + .setPrimaryHierarchy(getTestNodePrimaryHierarchy()) + .setIsFile(true) + .setIsFolder(false) + .setNodeType("cm:content") + .setPrimaryAssocQName("cm:testFile.txt") + .setCreatedByUser(new UserInfo("john.doe", "John", "Doe")) + .setCreatedAt(ZonedDateTime.now()) + .setModifiedByUser(new UserInfo("jane.doe", "Jane", "Doe")) + .setModifiedAt(ZonedDateTime.now()) + .setProperties(Map.of("cm:title", "test title", "cm:from", new Date(-2637887000L))) + .setAspectNames(Set.of("cm:titled", "cm:auditable")) + .setContent(new ContentInfo("text/plain", 16L, "UTF-8")) + .build(); + + EventData eventData = EventData. builder() + .setEventGroupId(getUUID()) + .setResource(resource) + .build(); // Add extensions ExtensionAttributes extAttributes = new ExtensionAttributesImpl(); @@ -103,15 +104,15 @@ public void nodeCreatedEventWithExtensionAttributes_marshalling() throws Excepti extAttributes.addExtension("doubleAttTest", 1234.56789); extAttributes.addExtension("boolAttTest", false); - RepoEvent> repoEvent = RepoEvent.>builder() - .setId(getUUID()) - .setSource(getSource()) - .setTime(ZonedDateTime.now()) - .setType(EventType.NODE_CREATED.getType()) - .setData(eventData) - .setDataschema(getDataSchema("nodeCreated")) - .setExtensionAttributes(extAttributes) - .build(); + RepoEvent> repoEvent = RepoEvent.> builder() + .setId(getUUID()) + .setSource(getSource()) + .setTime(ZonedDateTime.now()) + .setType(EventType.NODE_CREATED.getType()) + .setData(eventData) + .setDataschema(getDataSchema("nodeCreated")) + .setExtensionAttributes(extAttributes) + .build(); String result = OBJECT_MAPPER.writeValueAsString(repoEvent); String expectedJson = TestUtil.getResourceFileAsString("noAuth/NodeCreatedEventWithExtension.json"); @@ -124,40 +125,38 @@ public void nodeCreatedEventWithExtensionAttributes_unmarshalling() throws Excep { String nodeCreatedEventWithExtAttJson = TestUtil.getResourceFileAsString("noAuth/NodeCreatedEventWithExtension.json"); assertNotNull(nodeCreatedEventWithExtAttJson); - RepoEvent> result = OBJECT_MAPPER.readValue(nodeCreatedEventWithExtAttJson, new TypeReference<>() - { - }); + RepoEvent> result = OBJECT_MAPPER.readValue(nodeCreatedEventWithExtAttJson, new TypeReference<>() {}); NodeResource resource = NodeResource.builder() - .setId("7491120a-e2cb-478f-8599-ebf057cc0c7c") - .setName("testFile.txt") - .setPrimaryHierarchy(getTestNodePrimaryHierarchy()) - .setIsFile(true) - .setIsFolder(false) - .setNodeType("cm:content") - .setPrimaryAssocQName("cm:testFile.txt") - .setCreatedByUser(new UserInfo("john.doe", "John", "Doe")) - .setCreatedAt(parseTime("2020-04-27T12:37:03.555624+01:00")) - .setModifiedByUser(new UserInfo("jane.doe", "Jane", "Doe")) - .setModifiedAt(parseTime("2020-04-27T12:37:03.557956+01:00")) - .setProperties(Map.of("cm:title", "test title", "cm:from", "1969-12-01T11:15:13Z")) - .setAspectNames(Set.of("cm:titled", "cm:auditable")) - .setContent(new ContentInfo("text/plain", 16L, "UTF-8")) - .build(); - - EventData eventData = EventData.builder() - .setEventGroupId("cb645043-e7d2-4e51-b61d-e6d01582cbab") - .setResource(resource) - .build(); - - RepoEvent> repoEvent = RepoEvent.>builder() - .setId("97c1b36c-c569-4c66-8a31-7a8d0b6b804a") - .setSource(getSource()) - .setTime(parseTime("2020-04-27T12:37:03.560134+01:00")) - .setType(EventType.NODE_CREATED.getType()) - .setData(eventData) - .setDataschema(getDataSchema("nodeCreated")) - .build(); + .setId("7491120a-e2cb-478f-8599-ebf057cc0c7c") + .setName("testFile.txt") + .setPrimaryHierarchy(getTestNodePrimaryHierarchy()) + .setIsFile(true) + .setIsFolder(false) + .setNodeType("cm:content") + .setPrimaryAssocQName("cm:testFile.txt") + .setCreatedByUser(new UserInfo("john.doe", "John", "Doe")) + .setCreatedAt(parseTime("2020-04-27T12:37:03.555624+01:00")) + .setModifiedByUser(new UserInfo("jane.doe", "Jane", "Doe")) + .setModifiedAt(parseTime("2020-04-27T12:37:03.557956+01:00")) + .setProperties(Map.of("cm:title", "test title", "cm:from", "1969-12-01T11:15:13Z")) + .setAspectNames(Set.of("cm:titled", "cm:auditable")) + .setContent(new ContentInfo("text/plain", 16L, "UTF-8")) + .build(); + + EventData eventData = EventData. builder() + .setEventGroupId("cb645043-e7d2-4e51-b61d-e6d01582cbab") + .setResource(resource) + .build(); + + RepoEvent> repoEvent = RepoEvent.> builder() + .setId("97c1b36c-c569-4c66-8a31-7a8d0b6b804a") + .setSource(getSource()) + .setTime(parseTime("2020-04-27T12:37:03.560134+01:00")) + .setType(EventType.NODE_CREATED.getType()) + .setData(eventData) + .setDataschema(getDataSchema("nodeCreated")) + .build(); assertEquals(repoEvent.getId(), result.getId()); assertEquals(repoEvent.getType(), result.getType()); @@ -170,7 +169,7 @@ public void nodeCreatedEventWithExtensionAttributes_unmarshalling() throws Excep // Get the extension attributes map ExtensionAttributes resultExtensionAttributes = result.getExtensionAttributes(); - assertNotNull("There should have been an extension.", resultExtensionAttributes); + assertNotNull(resultExtensionAttributes, "There should have been an extension."); // Get the extension with the name 'client' Object extObjectValue = resultExtensionAttributes.getExtension("extObject"); @@ -195,10 +194,10 @@ public void nodeCreatedEventWithExtensionAttributes_unmarshalling() throws Excep public static class ExtensionTestObject { - private String id; - private int intProp; - private double doubleProp; - private boolean boolProp; + private String id; + private int intProp; + private double doubleProp; + private boolean boolProp; private List listProp; private Set setProp; private Map mapProp; @@ -285,19 +284,19 @@ public boolean equals(Object o) return false; } return getIntProp() == that.getIntProp() - && Double.compare(that.getDoubleProp(), getDoubleProp()) == 0 - && isBoolProp() == that.isBoolProp() - && Objects.equals(getId(), that.getId()) - && Objects.equals(getListProp(), that.getListProp()) - && Objects.equals(getSetProp(), that.getSetProp()) - && Objects.equals(getMapProp(), that.getMapProp()); + && Double.compare(that.getDoubleProp(), getDoubleProp()) == 0 + && isBoolProp() == that.isBoolProp() + && Objects.equals(getId(), that.getId()) + && Objects.equals(getListProp(), that.getListProp()) + && Objects.equals(getSetProp(), that.getSetProp()) + && Objects.equals(getMapProp(), that.getMapProp()); } @Override public int hashCode() { return Objects.hash(getId(), getIntProp(), getDoubleProp(), isBoolProp(), - getListProp(), getSetProp(), getMapProp()); + getListProp(), getSetProp(), getMapProp()); } } } diff --git a/src/test/java/org/alfresco/repo/event/v1/model/schema/ChildAssociationResource.java b/src/test/java/org/alfresco/repo/event/v1/model/schema/ChildAssociationResource.java index bcc7822..3f75112 100644 --- a/src/test/java/org/alfresco/repo/event/v1/model/schema/ChildAssociationResource.java +++ b/src/test/java/org/alfresco/repo/event/v1/model/schema/ChildAssociationResource.java @@ -25,11 +25,11 @@ */ package org.alfresco.repo.event.v1.model.schema; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + import org.alfresco.repo.event.v1.model.ChildAssocInfo; import org.alfresco.repo.event.v1.model.Resource; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; - /** * Event data object to generate the JSON schema for {@code ChildAssociationResource}. * @@ -40,15 +40,14 @@ public class ChildAssociationResource implements Resource { @Required - private String assocType; + private String assocType; @Required private ChildAssocInfo parent; @Required private ChildAssocInfo child; public ChildAssociationResource() - { - } + {} public String getAssocType() { diff --git a/src/test/java/org/alfresco/repo/event/v1/model/schema/EventDataWithResourceBefore.java b/src/test/java/org/alfresco/repo/event/v1/model/schema/EventDataWithResourceBefore.java index bb0bf9e..2470ec0 100644 --- a/src/test/java/org/alfresco/repo/event/v1/model/schema/EventDataWithResourceBefore.java +++ b/src/test/java/org/alfresco/repo/event/v1/model/schema/EventDataWithResourceBefore.java @@ -25,11 +25,11 @@ */ package org.alfresco.repo.event.v1.model.schema; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + import org.alfresco.repo.event.v1.model.DataAttributes; import org.alfresco.repo.event.v1.model.Resource; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; - /** * Event data object to generate the JSON schema for the node update event. * @@ -49,8 +49,7 @@ public class EventDataWithResourceBefore implements DataAttr private R resourceBefore; public EventDataWithResourceBefore() - { - } + {} @Override public String getEventGroupId() diff --git a/src/test/java/org/alfresco/repo/event/v1/model/schema/EventDataWithoutResourceBefore.java b/src/test/java/org/alfresco/repo/event/v1/model/schema/EventDataWithoutResourceBefore.java index 6e3f3c4..22158c9 100644 --- a/src/test/java/org/alfresco/repo/event/v1/model/schema/EventDataWithoutResourceBefore.java +++ b/src/test/java/org/alfresco/repo/event/v1/model/schema/EventDataWithoutResourceBefore.java @@ -25,12 +25,12 @@ */ package org.alfresco.repo.event.v1.model.schema; -import org.alfresco.repo.event.v1.model.DataAttributes; -import org.alfresco.repo.event.v1.model.Resource; - import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import org.alfresco.repo.event.v1.model.DataAttributes; +import org.alfresco.repo.event.v1.model.Resource; + /** * Event data object to generate the JSON schema without {@code resourceBefore} property. * @@ -47,8 +47,7 @@ public class EventDataWithoutResourceBefore implements DataA private R resource; public EventDataWithoutResourceBefore() - { - } + {} @Override public String getEventGroupId() diff --git a/src/test/java/org/alfresco/repo/event/v1/model/schema/NodeResource.java b/src/test/java/org/alfresco/repo/event/v1/model/schema/NodeResource.java index ffb45b1..57dec26 100644 --- a/src/test/java/org/alfresco/repo/event/v1/model/schema/NodeResource.java +++ b/src/test/java/org/alfresco/repo/event/v1/model/schema/NodeResource.java @@ -31,13 +31,13 @@ import java.util.Map; import java.util.Set; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + import org.alfresco.repo.event.v1.model.ContentInfo; import org.alfresco.repo.event.v1.model.Resource; import org.alfresco.repo.event.v1.model.UserInfo; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; - /** * Event data object to generate the JSON schema for {@code NodeResource}. * @@ -48,23 +48,22 @@ public class NodeResource implements Resource { @Required - private String id; - private String name; - private String nodeType; - private Boolean file; - private Boolean folder; - private UserInfo createdByUser; - private ZonedDateTime createdAt; - private UserInfo modifiedByUser; - private ZonedDateTime modifiedAt; - private ContentInfo content; - private List primaryHierarchy; + private String id; + private String name; + private String nodeType; + private Boolean file; + private Boolean folder; + private UserInfo createdByUser; + private ZonedDateTime createdAt; + private UserInfo modifiedByUser; + private ZonedDateTime modifiedAt; + private ContentInfo content; + private List primaryHierarchy; private Map properties; - private Set aspectNames; + private Set aspectNames; public NodeResource() - { - } + {} public String getId() { diff --git a/src/test/java/org/alfresco/repo/event/v1/model/schema/PeerAssociationResource.java b/src/test/java/org/alfresco/repo/event/v1/model/schema/PeerAssociationResource.java index 8d75a49..aadb7b0 100644 --- a/src/test/java/org/alfresco/repo/event/v1/model/schema/PeerAssociationResource.java +++ b/src/test/java/org/alfresco/repo/event/v1/model/schema/PeerAssociationResource.java @@ -25,11 +25,11 @@ */ package org.alfresco.repo.event.v1.model.schema; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + import org.alfresco.repo.event.v1.model.PeerAssocInfo; import org.alfresco.repo.event.v1.model.Resource; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; - /** * Event data object to generate the JSON schema for {@code PeerAssociationResource}. * @@ -40,15 +40,14 @@ public class PeerAssociationResource implements Resource { @Required - private String assocType; + private String assocType; @Required private PeerAssocInfo source; @Required private PeerAssocInfo target; public PeerAssociationResource() - { - } + {} public String getAssocType() { diff --git a/src/test/java/org/alfresco/repo/event/v1/model/schema/RepoEvent.java b/src/test/java/org/alfresco/repo/event/v1/model/schema/RepoEvent.java index 9f14a1d..e34b2a7 100644 --- a/src/test/java/org/alfresco/repo/event/v1/model/schema/RepoEvent.java +++ b/src/test/java/org/alfresco/repo/event/v1/model/schema/RepoEvent.java @@ -28,12 +28,12 @@ import java.net.URI; import java.time.ZonedDateTime; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + import org.alfresco.repo.event.EventAttributes; import org.alfresco.repo.event.v1.model.DataAttributes; import org.alfresco.repo.event.v1.model.Resource; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; - /** * Event data object to generate the JSON schema for {@code RepoEvent}. * @@ -44,21 +44,21 @@ public class RepoEvent> implements EventAttributes { @Required - private String specversion; + private String specversion; @Required - private String type; + private String type; @Required - private String id; + private String id; @Required - private URI source; + private URI source; @Required private ZonedDateTime time; @Required - private URI dataschema; + private URI dataschema; @Required - private String datacontenttype; + private String datacontenttype; @Required - private D data; + private D data; @Override public String getSpecversion() diff --git a/src/test/java/org/alfresco/repo/event/v1/model/schema/Required.java b/src/test/java/org/alfresco/repo/event/v1/model/schema/Required.java index b758ad4..c0ab6ec 100644 --- a/src/test/java/org/alfresco/repo/event/v1/model/schema/Required.java +++ b/src/test/java/org/alfresco/repo/event/v1/model/schema/Required.java @@ -32,7 +32,6 @@ import java.lang.annotation.Retention; import java.lang.annotation.Target; - /** * @author Jamal Kaabi-Mofrad */ @@ -40,5 +39,4 @@ @Retention(RUNTIME) @Documented public @interface Required -{ -} +{} diff --git a/src/test/java/org/alfresco/repo/event/v1/model/schema/generator/JsonSchemaGeneratorTest.java b/src/test/java/org/alfresco/repo/event/v1/model/schema/generator/JsonSchemaGeneratorTest.java index 2b85b16..9cd9402 100644 --- a/src/test/java/org/alfresco/repo/event/v1/model/schema/generator/JsonSchemaGeneratorTest.java +++ b/src/test/java/org/alfresco/repo/event/v1/model/schema/generator/JsonSchemaGeneratorTest.java @@ -36,17 +36,6 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import org.alfresco.repo.event.v1.model.DataAttributes; -import org.alfresco.repo.event.v1.model.Resource; -import org.alfresco.repo.event.v1.model.schema.ChildAssociationResource; -import org.alfresco.repo.event.v1.model.schema.EventDataWithResourceBefore; -import org.alfresco.repo.event.v1.model.schema.EventDataWithoutResourceBefore; -import org.alfresco.repo.event.v1.model.schema.NodeResource; -import org.alfresco.repo.event.v1.model.schema.PeerAssociationResource; -import org.alfresco.repo.event.v1.model.schema.RepoEvent; -import org.alfresco.repo.event.v1.model.schema.Required; -import org.junit.Test; - import com.fasterxml.jackson.databind.JsonNode; import com.github.victools.jsonschema.generator.OptionPreset; import com.github.victools.jsonschema.generator.SchemaGenerator; @@ -56,6 +45,17 @@ import com.github.victools.jsonschema.generator.TypeContext; import com.github.victools.jsonschema.module.jackson.JacksonModule; import com.github.victools.jsonschema.module.jackson.JacksonOption; +import org.junit.jupiter.api.Test; + +import org.alfresco.repo.event.v1.model.DataAttributes; +import org.alfresco.repo.event.v1.model.Resource; +import org.alfresco.repo.event.v1.model.schema.ChildAssociationResource; +import org.alfresco.repo.event.v1.model.schema.EventDataWithResourceBefore; +import org.alfresco.repo.event.v1.model.schema.EventDataWithoutResourceBefore; +import org.alfresco.repo.event.v1.model.schema.NodeResource; +import org.alfresco.repo.event.v1.model.schema.PeerAssociationResource; +import org.alfresco.repo.event.v1.model.schema.RepoEvent; +import org.alfresco.repo.event.v1.model.schema.Required; /** * @author Jamal Kaabi-Mofrad @@ -64,10 +64,7 @@ public class JsonSchemaGeneratorTest { enum EventEntry { - NODE_ENTRY(List.of("nodeCreated.json", "nodeDeleted.json")), - NODE_UPDATED_ENTRY(List.of("nodeUpdated.json")), - CHILD_ASSOC_ENTRY(List.of("childAssocCreated.json", "childAssocDeleted.json")), - PEER_ASSOC_ENTRY(List.of("peerAssocCreated.json", "peerAssocDeleted.json")); + NODE_ENTRY(List.of("nodeCreated.json", "nodeDeleted.json")), NODE_UPDATED_ENTRY(List.of("nodeUpdated.json")), CHILD_ASSOC_ENTRY(List.of("childAssocCreated.json", "childAssocDeleted.json")), PEER_ASSOC_ENTRY(List.of("peerAssocCreated.json", "peerAssocDeleted.json")); private final List fileNames; @@ -97,8 +94,7 @@ private SchemaGeneratorConfigBuilder getConfigBuilder(final EventEntry entry) { JacksonModule module = new JacksonModule(JacksonOption.RESPECT_JSONPROPERTY_ORDER); - SchemaGeneratorConfigBuilder configBuilder = - new SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_2019_09, OptionPreset.PLAIN_JSON).with(module); + SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_2019_09, OptionPreset.PLAIN_JSON).with(module); configBuilder.forTypesInGeneral().withSubtypeResolver((declaredType, generationContext) -> { if (declaredType.getErasedType() == Resource.class) @@ -106,12 +102,12 @@ private SchemaGeneratorConfigBuilder getConfigBuilder(final EventEntry entry) TypeContext typeContext = generationContext.getTypeContext(); switch (entry) { - case NODE_ENTRY: - return List.of(typeContext.resolveSubtype(declaredType, NodeResource.class)); - case CHILD_ASSOC_ENTRY: - return List.of(typeContext.resolveSubtype(declaredType, ChildAssociationResource.class)); - case PEER_ASSOC_ENTRY: - return List.of(typeContext.resolveSubtype(declaredType, PeerAssociationResource.class)); + case NODE_ENTRY: + return List.of(typeContext.resolveSubtype(declaredType, NodeResource.class)); + case CHILD_ASSOC_ENTRY: + return List.of(typeContext.resolveSubtype(declaredType, ChildAssociationResource.class)); + case PEER_ASSOC_ENTRY: + return List.of(typeContext.resolveSubtype(declaredType, PeerAssociationResource.class)); } } @@ -134,8 +130,8 @@ private SchemaGeneratorConfigBuilder getConfigBuilder(final EventEntry entry) if (field.getDeclaredType().getErasedType() == URI.class) { return Stream.of(String.class) - .map(specificSubtype -> field.getContext().resolve(String.class)) - .collect(Collectors.toList()); + .map(specificSubtype -> field.getContext().resolve(String.class)) + .collect(Collectors.toList()); } return null; }); @@ -153,12 +149,12 @@ private void writeToFile(JsonNode jsonSchema, String fileName) File outputDir = new File("target/schema/"); if (!outputDir.exists()) { - //noinspection ResultOfMethodCallIgnored + // noinspection ResultOfMethodCallIgnored outputDir.mkdirs(); } try (FileOutputStream outputStream = new FileOutputStream(new File(outputDir, fileName)); - PrintWriter writer = new PrintWriter(new OutputStreamWriter(outputStream, StandardCharsets.UTF_8))) + PrintWriter writer = new PrintWriter(new OutputStreamWriter(outputStream, StandardCharsets.UTF_8))) { writer.print(jsonSchema.toPrettyString()); }