From f2ef2711dfe3d3a7bed7b91b7836cdf4daab523e Mon Sep 17 00:00:00 2001 From: Kacper Magdziarz <95610011+kmagdziarz@users.noreply.github.com> Date: Tue, 26 Nov 2024 15:56:25 +0100 Subject: [PATCH] [ACS-9024] Merge enterprise event model into the community one (#39) * [ACS-9024] Merge Enterprise Event Model into Community * [ACS-9024] Prepare for 1.0.0 release --- pom.xml | 4 +- .../repo/event/v1/model/EventData.java | 83 ++++- .../alfresco/repo/event/util/TestUtil.java | 6 +- .../repo/event/v1/model/EventTest.java | 318 +++++++++++++++++- .../model/extension/EventExtensionTest.java | 7 +- .../resources/auth/ChildAssocCreated.json | 30 ++ src/test/resources/auth/NodeCreatedEvent.json | 53 +++ src/test/resources/auth/NodeUpdatedEvent.json | 69 ++++ src/test/resources/auth/PeerAssocCreated.json | 26 ++ .../{ => noAuth}/ChildAssocCreated.json | 0 .../{ => noAuth}/NodeCreatedEvent.json | 0 .../NodeCreatedEventWithExtension.json | 0 .../{ => noAuth}/NodeUpdatedEvent.json | 0 .../{ => noAuth}/PeerAssocCreated.json | 0 14 files changed, 569 insertions(+), 27 deletions(-) create mode 100644 src/test/resources/auth/ChildAssocCreated.json create mode 100644 src/test/resources/auth/NodeCreatedEvent.json create mode 100644 src/test/resources/auth/NodeUpdatedEvent.json create mode 100644 src/test/resources/auth/PeerAssocCreated.json rename src/test/resources/{ => noAuth}/ChildAssocCreated.json (100%) rename src/test/resources/{ => noAuth}/NodeCreatedEvent.json (100%) rename src/test/resources/{ => noAuth}/NodeCreatedEventWithExtension.json (100%) rename src/test/resources/{ => noAuth}/NodeUpdatedEvent.json (100%) rename src/test/resources/{ => noAuth}/PeerAssocCreated.json (100%) diff --git a/pom.xml b/pom.xml index 51f0b4e..61eaf10 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ acs-event-model - 0.0.34-SNAPSHOT + 1.0.0-SNAPSHOT jar acs-event-model Alfresco Content Services Event Model @@ -64,7 +64,7 @@ commons-io commons-io - 2.7 + 2.14.0 test 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 728492b..864e963 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 @@ -26,6 +26,7 @@ package org.alfresco.repo.event.v1.model; import java.util.Objects; +import java.util.Set; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; @@ -51,11 +52,26 @@ public class EventData implements DataAttributes @JsonTypeInfo(use = Id.NAME) private final R resourceBefore; + // Ignored if authorities is disabled + @JsonInclude(Include.NON_NULL) + private final Set resourceReaderAuthorities; + + // Ignored if authorities is disabled + @JsonInclude(Include.NON_NULL) + private final Set resourceDeniedAuthorities; + + // Only relevant for AGS module + @JsonInclude(Include.NON_NULL) + private final Set resourceReaderSecurityControls; + private EventData(Builder builder) { this.eventGroupId = builder.eventGroupId; this.resource = builder.resource; this.resourceBefore = builder.resourceBefore; + this.resourceReaderAuthorities = builder.resourceReaderAuthorities; + this.resourceDeniedAuthorities = builder.resourceDeniedAuthorities; + this.resourceReaderSecurityControls = builder.resourceReaderSecurityControls; } public static Builder builder() @@ -81,6 +97,21 @@ public R getResourceBefore() return resourceBefore; } + public Set getResourceReaderAuthorities() + { + return resourceReaderAuthorities; + } + + public Set getResourceDeniedAuthorities() + { + return resourceDeniedAuthorities; + } + + public Set getResourceReaderSecurityControls() + { + return resourceReaderSecurityControls; + } + @Override public boolean equals(Object o) { @@ -88,20 +119,23 @@ public boolean equals(Object o) { return true; } - if (!(o instanceof EventData)) + if (!(o instanceof EventData that)) { return false; } - EventData eventData = (EventData) o; - return Objects.equals(eventGroupId, eventData.eventGroupId) - && Objects.equals(resource, eventData.resource) - && Objects.equals(resourceBefore, eventData.resourceBefore); + return Objects.equals(eventGroupId, that.eventGroupId) + && Objects.equals(resource, that.resource) + && Objects.equals(resourceBefore, that.resourceBefore) + && Objects.equals(resourceReaderAuthorities, that.resourceReaderAuthorities) + && Objects.equals(resourceDeniedAuthorities, that.resourceDeniedAuthorities) + && Objects.equals(resourceReaderSecurityControls, that.resourceReaderSecurityControls); } @Override public int hashCode() { - return Objects.hash(eventGroupId, resource, resourceBefore); + return Objects.hash(eventGroupId, resource, resourceBefore, resourceReaderAuthorities, + resourceDeniedAuthorities, resourceReaderSecurityControls); } @Override @@ -109,9 +143,12 @@ public String toString() { final StringBuilder sb = new StringBuilder(500); sb.append("EventData [eventGroupId=").append(eventGroupId) - .append(", resource=").append(resource) - .append(", resourceBefore=").append(resourceBefore) - .append(']'); + .append(", resource=").append(resource) + .append(", resourceBefore=").append(resourceBefore) + .append(", resourceReaderAuthorities=").append(resourceReaderAuthorities) + .append(", resourceDeniedAuthorities=").append(resourceDeniedAuthorities) + .append(", resourceReaderSecurityControls=").append(resourceReaderSecurityControls) + .append(']'); return sb.toString(); } @@ -121,9 +158,13 @@ public String toString() @JsonPOJOBuilder(withPrefix = "set") 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; public Builder setEventGroupId(String eventGroupId) { @@ -143,6 +184,24 @@ public Builder setResourceBefore(R resourceBefore) return this; } + public Builder setResourceReaderAuthorities(Set resourceReaderAuthorities) + { + this.resourceReaderAuthorities = resourceReaderAuthorities; + return this; + } + + public Builder setResourceDeniedAuthorities(Set resourceDeniedAuthorities) + { + this.resourceDeniedAuthorities = resourceDeniedAuthorities; + return this; + } + + public Builder setResourceReaderSecurityControls(Set resourceReaderSecurityControls) + { + this.resourceReaderSecurityControls = resourceReaderSecurityControls; + return this; + } + public EventData build() { return new EventData<>(this); 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 694037d..3ba4545 100644 --- a/src/test/java/org/alfresco/repo/event/util/TestUtil.java +++ b/src/test/java/org/alfresco/repo/event/util/TestUtil.java @@ -100,7 +100,11 @@ public class TestUtil 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("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); 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 8e6cfce..0bb0bcd 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 @@ -91,7 +91,7 @@ public void nodeCreatedEvent_marshalling() throws Exception .build(); String result = OBJECT_MAPPER.writeValueAsString(repoEvent); - String expectedJson = TestUtil.getResourceFileAsString("NodeCreatedEvent.json"); + String expectedJson = TestUtil.getResourceFileAsString("noAuth/NodeCreatedEvent.json"); // Compare the Json files checkExpectedJsonBody(expectedJson, result); } @@ -99,7 +99,7 @@ public void nodeCreatedEvent_marshalling() throws Exception @Test public void nodeCreatedEvent_unmarshalling() throws Exception { - String nodeCreatedEventJson = TestUtil.getResourceFileAsString("NodeCreatedEvent.json"); + String nodeCreatedEventJson = TestUtil.getResourceFileAsString("noAuth/NodeCreatedEvent.json"); assertNotNull(nodeCreatedEventJson); RepoEvent> result = OBJECT_MAPPER.readValue(nodeCreatedEventJson, new TypeReference<>() { @@ -186,7 +186,7 @@ public void nodeUpdatedEvent_marshalling() throws Exception .build(); String result = OBJECT_MAPPER.writeValueAsString(repoEvent); - String expectedJson = TestUtil.getResourceFileAsString("NodeUpdatedEvent.json"); + String expectedJson = TestUtil.getResourceFileAsString("noAuth/NodeUpdatedEvent.json"); // Compare the Json files checkExpectedJsonBody(expectedJson, result); } @@ -194,7 +194,7 @@ public void nodeUpdatedEvent_marshalling() throws Exception @Test public void nodeUpdatedEvent_unmarshalling() throws Exception { - String nodeUpdatedEventJson = TestUtil.getResourceFileAsString("NodeUpdatedEvent.json"); + String nodeUpdatedEventJson = TestUtil.getResourceFileAsString("noAuth/NodeUpdatedEvent.json"); assertNotNull(nodeUpdatedEventJson); RepoEvent> result = OBJECT_MAPPER.readValue(nodeUpdatedEventJson, new TypeReference<>() { @@ -268,7 +268,7 @@ public void childAssocCreatedEvent_marshalling() throws Exception .build(); String result = OBJECT_MAPPER.writeValueAsString(repoEvent); - String expectedJson = TestUtil.getResourceFileAsString("ChildAssocCreated.json"); + String expectedJson = TestUtil.getResourceFileAsString("noAuth/ChildAssocCreated.json"); // Compare the Json files checkExpectedJsonBody(expectedJson, result); } @@ -276,7 +276,7 @@ public void childAssocCreatedEvent_marshalling() throws Exception @Test public void childAssocCreatedEvent_unmarshalling() throws Exception { - String childAssocCreatedEventJson = TestUtil.getResourceFileAsString("ChildAssocCreated.json"); + String childAssocCreatedEventJson = TestUtil.getResourceFileAsString("noAuth/ChildAssocCreated.json"); assertNotNull(childAssocCreatedEventJson); RepoEvent> result = OBJECT_MAPPER.readValue(childAssocCreatedEventJson, new TypeReference<>() { @@ -324,7 +324,7 @@ public void peerAssocCreatedEvent_marshalling() throws Exception .build(); String result = OBJECT_MAPPER.writeValueAsString(repoEvent); - String expectedJson = TestUtil.getResourceFileAsString("PeerAssocCreated.json"); + String expectedJson = TestUtil.getResourceFileAsString("noAuth/PeerAssocCreated.json"); // Compare the Json files checkExpectedJsonBody(expectedJson, result); } @@ -332,7 +332,7 @@ public void peerAssocCreatedEvent_marshalling() throws Exception @Test public void peerAssocCreatedEvent_unmarshalling() throws Exception { - String peerAssocCreatedEventJson = TestUtil.getResourceFileAsString("PeerAssocCreated.json"); + String peerAssocCreatedEventJson = TestUtil.getResourceFileAsString("noAuth/PeerAssocCreated.json"); assertNotNull(peerAssocCreatedEventJson); RepoEvent> result = OBJECT_MAPPER.readValue(peerAssocCreatedEventJson, new TypeReference<>() { @@ -359,4 +359,306 @@ public void peerAssocCreatedEvent_unmarshalling() throws Exception assertEquals(expectedRepoEvent, result); } + @Test + public void nodeCreatedWithAuthoritiesEvent_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") + .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")) + .setAspectNames(Set.of("cm:titled", "cm:auditable")) + .setContent(new ContentInfo("text/plain", 16L, "UTF-8")) + .build(); + + 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()) + .setSource(getSource()) + .setTime(ZonedDateTime.now()) + .setType("org.alfresco.event.node.Created") + .setData(eventData) + .setDataschema(getDataSchema("nodeCreated")) + .build(); + + String result = OBJECT_MAPPER.writeValueAsString(repoEvent); + String expectedJson = TestUtil.getResourceFileAsString("auth/NodeCreatedEvent.json"); + // Compare the Json files + checkExpectedJsonBody(expectedJson, result); + } + + @Test + public void nodeCreatedWithAuthoritiesEvent_unmarshalling() throws Exception + { + String nodeCreatedEventJson = TestUtil.getResourceFileAsString("auth/NodeCreatedEvent.json"); + assertNotNull(nodeCreatedEventJson); + 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") + .setCreatedByUser(new UserInfo("john.doe", "John", "Doe")) + .setCreatedAt(parseTime("2020-06-10T12:37:03.555624+01:00")) + .setModifiedByUser(new UserInfo("jane.doe", "Jane", "Doe")) + .setModifiedAt(parseTime("2020-06-10T12:37:03.557956+01:00")) + .setProperties(Map.of("cm:title", "test title")) + .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) + .setResourceReaderAuthorities(Set.of("GROUP_EVERYONE", "GROUP_ONE", "GROUP_TWO")) + .setResourceDeniedAuthorities(Set.of()) + .build(); + + 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") + .setData(eventData) + .setDataschema(getDataSchema("nodeCreated")) + .build(); + + assertEquals(repoEvent, result); + } + + @Test + public void nodeUpdatedWithAuthoritiesEvent_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.")) + .setAspectNames(Set.of("cm:titled", "cm:auditable")) + .setContent(new ContentInfo("text/plain", 16L, "UTF-8")) + .build(); + + NodeResource resourceBefore = NodeResource.builder() + .setModifiedByUser(new UserInfo("jane.doe", "Jane", "Doe")) + .setModifiedAt(ZonedDateTime.now()) + .setProperties(Map.of("cm:title", "test title")) + .build(); + + EventData eventData = EventData.builder() + .setEventGroupId(getUUID()) + .setResource(resource) + .setResourceBefore(resourceBefore) + .setResourceReaderAuthorities(Set.of("GROUP_ONE", "GROUP_THREE")) + .setResourceDeniedAuthorities(Set.of("GROUP_TWO")) + .setResourceReaderSecurityControls(Set.of("e428663f-9171-42e2-b233-d8f2cd3f54f7:mF2foUuA")) + .build(); + + RepoEvent> repoEvent = RepoEvent.>builder().setId(getUUID()) + .setSource(getSource()) + .setTime(ZonedDateTime.now()) + .setType("org.alfresco.event.node.Updated") + .setData(eventData) + .setDataschema(getDataSchema("nodeUpdated")) + .build(); + + String result = OBJECT_MAPPER.writeValueAsString(repoEvent); + String expectedJson = TestUtil.getResourceFileAsString("auth/NodeUpdatedEvent.json"); + // Compare the Json files + checkExpectedJsonBody(expectedJson, result); + } + + @Test + public void nodeUpdatedWithAuthoritiesEvent_unmarshalling() throws Exception + { + String nodeUpdatedEventJson = TestUtil.getResourceFileAsString("auth/NodeUpdatedEvent.json"); + assertNotNull(nodeUpdatedEventJson); + 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") + .setCreatedByUser(new UserInfo("john.doe", "John", "Doe")) + .setCreatedAt(parseTime("2020-06-10T14:25:59.852475+01:00")) + .setModifiedByUser(new UserInfo("jane.doe", "Jane", "Doe")) + .setModifiedAt(parseTime("2020-06-10T14:25:59.854153+01:00")) + .setProperties(Map.of("cm:title", "test title2", "cm:description", "test description.")) + .setAspectNames(Set.of("cm:titled", "cm:auditable")) + .setContent(new ContentInfo("text/plain", 16L, "UTF-8")) + .build(); + + NodeResource expectedResourceBefore = NodeResource.builder() + .setModifiedByUser(new UserInfo("jane.doe", "Jane", "Doe")) + .setModifiedAt(parseTime("2020-06-10T14:25:59.854558+01:00")) + .setProperties(Map.of("cm:title", "test title")) + .build(); + + EventData expectedEventData = EventData.builder() + .setEventGroupId("ce852a52-609e-4b7d-8438-04e211fd76a0") + .setResource(expectedResource) + .setResourceBefore(expectedResourceBefore) + .setResourceReaderAuthorities(Set.of("GROUP_ONE", "GROUP_THREE")) + .setResourceDeniedAuthorities(Set.of("GROUP_TWO")) + .setResourceReaderSecurityControls(Set.of("e428663f-9171-42e2-b233-d8f2cd3f54f7:mF2foUuA")) + .build(); + + 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") + .setData(expectedEventData) + .setDataschema(getDataSchema("nodeUpdated")) + .build(); + + assertEquals(expectedRepoEvent, result); + } + + @Test + public void childAssocCreatedWithAuthoritiesEvent_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) + .setResourceReaderAuthorities(Set.of("GROUP_EVERYONE", "GROUP_ONE")) + .setResourceDeniedAuthorities(Set.of("GROUP_TWO")) + .build(); + + RepoEvent> repoEvent = RepoEvent.>builder() + .setId(getUUID()) + .setSource(getSource()) + .setTime(ZonedDateTime.now()) + .setType("org.alfresco.event.assoc.child.Created") + .setData(eventData) + .setDataschema(getDataSchema("childAssocCreated")) + .build(); + + String result = OBJECT_MAPPER.writeValueAsString(repoEvent); + String expectedJson = TestUtil.getResourceFileAsString("auth/ChildAssocCreated.json"); + // Compare the Json files + checkExpectedJsonBody(expectedJson, result); + } + + @Test + public void childAssocCreatedWithAuthoritiesEvent_unmarshalling() throws Exception + { + String childAssocCreatedEventJson = TestUtil.getResourceFileAsString("auth/ChildAssocCreated.json"); + assertNotNull(childAssocCreatedEventJson); + 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) + .setResourceReaderAuthorities(Set.of("GROUP_EVERYONE", "GROUP_ONE")) + .setResourceDeniedAuthorities(Set.of("GROUP_TWO")) + .build(); + + RepoEvent> expectedRepoEvent = RepoEvent.>builder() + .setId("928c28fc-da23-441d-bb8b-72b068a9ceb5") + .setSource(getSource()) + .setTime(parseTime("2020-06-10T09:56:52.235411+01:00")) + .setType("org.alfresco.event.assoc.child.Created") + .setData(expectedEventData) + .setDataschema(getDataSchema("childAssocCreated")) + .build(); + + assertEquals(expectedRepoEvent, result); + } + + @Test + public void peerAssocCreatedWithAuthoritiesEvent_marshalling() throws Exception + { + PeerAssociationResource peerAssocResource = new PeerAssociationResource(getUUID(), getUUID(), "cm:references"); + + EventData eventData = EventData.builder() + .setEventGroupId(getUUID()) + .setResource(peerAssocResource) + .setResourceReaderAuthorities(Set.of()) + .setResourceDeniedAuthorities(Set.of("GROUP_TWO")) + .build(); + + RepoEvent> repoEvent = RepoEvent.>builder() + .setId(getUUID()) + .setSource(getSource()) + .setTime(ZonedDateTime.now()) + .setType("org.alfresco.event.assoc.peer.Created") + .setData(eventData) + .setDataschema(getDataSchema("peerAssocCreated")) + .build(); + + String result = OBJECT_MAPPER.writeValueAsString(repoEvent); + String expectedJson = TestUtil.getResourceFileAsString("auth/PeerAssocCreated.json"); + // Compare the Json files + checkExpectedJsonBody(expectedJson, result); + } + + @Test + public void peerAssocCreatedWithAuthoritiesEvent_unmarshalling() throws Exception + { + String peerAssocCreatedEventJson = TestUtil.getResourceFileAsString("auth/PeerAssocCreated.json"); + assertNotNull(peerAssocCreatedEventJson); + 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) + .setResourceReaderAuthorities(Set.of()) + .setResourceDeniedAuthorities(Set.of("GROUP_TWO")) + .build(); + + RepoEvent> expectedRepoEvent = RepoEvent.>builder() + .setId("8677a369-a30d-469e-b313-e5bf1b590c8e") + .setSource(getSource()) + .setTime(parseTime("2020-06-10T10:36:21.291392+01:00")) + .setType("org.alfresco.event.assoc.peer.Created") + .setData(expectedEventData) + .setDataschema(getDataSchema("peerAssocCreated")) + .build(); + + assertEquals(expectedRepoEvent, result); + } } 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 841ee31..f398358 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 @@ -114,7 +114,7 @@ public void nodeCreatedEventWithExtensionAttributes_marshalling() throws Excepti .build(); String result = OBJECT_MAPPER.writeValueAsString(repoEvent); - String expectedJson = TestUtil.getResourceFileAsString("NodeCreatedEventWithExtension.json"); + String expectedJson = TestUtil.getResourceFileAsString("noAuth/NodeCreatedEventWithExtension.json"); // Compare the Json files checkExpectedJsonBody(expectedJson, result); } @@ -122,7 +122,7 @@ public void nodeCreatedEventWithExtensionAttributes_marshalling() throws Excepti @Test public void nodeCreatedEventWithExtensionAttributes_unmarshalling() throws Exception { - String nodeCreatedEventWithExtAttJson = TestUtil.getResourceFileAsString("NodeCreatedEventWithExtension.json"); + String nodeCreatedEventWithExtAttJson = TestUtil.getResourceFileAsString("noAuth/NodeCreatedEventWithExtension.json"); assertNotNull(nodeCreatedEventWithExtAttJson); RepoEvent> result = OBJECT_MAPPER.readValue(nodeCreatedEventWithExtAttJson, new TypeReference<>() { @@ -280,11 +280,10 @@ public boolean equals(Object o) { return true; } - if (!(o instanceof ExtensionTestObject)) + if (!(o instanceof ExtensionTestObject that)) { return false; } - ExtensionTestObject that = (ExtensionTestObject) o; return getIntProp() == that.getIntProp() && Double.compare(that.getDoubleProp(), getDoubleProp()) == 0 && isBoolProp() == that.isBoolProp() diff --git a/src/test/resources/auth/ChildAssocCreated.json b/src/test/resources/auth/ChildAssocCreated.json new file mode 100644 index 0000000..2e25465 --- /dev/null +++ b/src/test/resources/auth/ChildAssocCreated.json @@ -0,0 +1,30 @@ +{ + "specversion": "1.0", + "type": "org.alfresco.event.assoc.child.Created", + "id": "928c28fc-da23-441d-bb8b-72b068a9ceb5", + "source": "/f6d21231-618e-4f12-a920-e498660c5b9d", + "time": "2020-06-10T09:56:52.235411+01:00", + "dataschema": "https://api.alfresco.com/schema/event/repo/v1/childAssocCreated", + "datacontenttype": "application/json", + "data": { + "eventGroupId": "d933857e-5f4f-406e-aa5f-c747901f5a8f", + "resource": { + "@type": "ChildAssociationResource", + "assocType": "cm:contains", + "assocQName": "cm:213131-1234-1235-5432-12039400a121", + "parent": { + "id": "7624edb6-6f28-4130-a4fb-4a5362807a05" + }, + "child": { + "id": "5d9f3d6f-9802-4bb6-8ad3-0f9261d08894" + } + }, + "resourceReaderAuthorities": [ + "GROUP_EVERYONE", + "GROUP_ONE" + ], + "resourceDeniedAuthorities": [ + "GROUP_TWO" + ] + } +} diff --git a/src/test/resources/auth/NodeCreatedEvent.json b/src/test/resources/auth/NodeCreatedEvent.json new file mode 100644 index 0000000..ad78a35 --- /dev/null +++ b/src/test/resources/auth/NodeCreatedEvent.json @@ -0,0 +1,53 @@ +{ + "specversion": "1.0", + "type": "org.alfresco.event.node.Created", + "id": "97c1b36c-c569-4c66-8a31-7a8d0b6b804a", + "source": "/f6d21231-618e-4f12-a920-e498660c5b9d", + "time": "2020-06-10T12:37:03.560134+01:00", + "dataschema": "https://api.alfresco.com/schema/event/repo/v1/nodeCreated", + "datacontenttype": "application/json", + "data": { + "eventGroupId": "cb645043-e7d2-4e51-b61d-e6d01582cbab", + "resource": { + "@type": "NodeResource", + "id": "7491120a-e2cb-478f-8599-ebf057cc0c7c", + "name": "testFile.txt", + "primaryAssocQName": "cm:testFile.txt", + "nodeType": "cm:content", + "isFolder": false, + "isFile": true, + "createdByUser": { + "id": "john.doe", + "displayName": "John Doe" + }, + "createdAt": "2020-06-10T12:37:03.555624+01:00", + "modifiedByUser": { + "id": "jane.doe", + "displayName": "Jane Doe" + }, + "modifiedAt": "2020-06-10T12:37:03.557956+01:00", + "content": { + "mimeType": "text/plain", + "sizeInBytes": 16, + "encoding": "UTF-8" + }, + "primaryHierarchy": [ + "521aac1c-20eb-444b-a137-2da3d35ee1a8", + "2641bbe1-39ff-44dc-b47f-736552ad46cc" + ], + "properties": { + "cm:title": "test title" + }, + "aspectNames": [ + "cm:titled", + "cm:auditable" + ] + }, + "resourceReaderAuthorities": [ + "GROUP_EVERYONE", + "GROUP_ONE", + "GROUP_TWO" + ], + "resourceDeniedAuthorities": [] + } +} diff --git a/src/test/resources/auth/NodeUpdatedEvent.json b/src/test/resources/auth/NodeUpdatedEvent.json new file mode 100644 index 0000000..adbcd86 --- /dev/null +++ b/src/test/resources/auth/NodeUpdatedEvent.json @@ -0,0 +1,69 @@ +{ + "specversion": "1.0", + "type": "org.alfresco.event.node.Updated", + "id": "df708027-e0a8-4b30-92a5-0d19235a7800", + "source": "/f6d21231-618e-4f12-a920-e498660c5b9d", + "time": "2020-06-10T14:25:59.855866+01:00", + "dataschema": "https://api.alfresco.com/schema/event/repo/v1/nodeUpdated", + "datacontenttype": "application/json", + "data": { + "eventGroupId": "ce852a52-609e-4b7d-8438-04e211fd76a0", + "resource": { + "@type": "NodeResource", + "id": "d366f805-853f-46ac-a81c-af9c257ee876", + "name": "testFile.txt", + "primaryAssocQName": "cm:testFile.txt", + "nodeType": "cm:content", + "isFolder": false, + "isFile": true, + "createdByUser": { + "id": "john.doe", + "displayName": "John Doe" + }, + "createdAt": "2020-06-10T14:25:59.852475+01:00", + "modifiedByUser": { + "id": "jane.doe", + "displayName": "Jane Doe" + }, + "modifiedAt": "2020-06-10T14:25:59.854153+01:00", + "content": { + "mimeType": "text/plain", + "sizeInBytes": 16, + "encoding": "UTF-8" + }, + "primaryHierarchy": [ + "521aac1c-20eb-444b-a137-2da3d35ee1a8", + "2641bbe1-39ff-44dc-b47f-736552ad46cc" + ], + "properties": { + "cm:description": "test description.", + "cm:title": "test title2" + }, + "aspectNames": [ + "cm:titled", + "cm:auditable" + ] + }, + "resourceBefore": { + "@type": "NodeResource", + "modifiedByUser": { + "id": "jane.doe", + "displayName": "Jane Doe" + }, + "modifiedAt": "2020-06-10T14:25:59.854558+01:00", + "properties": { + "cm:title": "test title" + } + }, + "resourceReaderAuthorities": [ + "GROUP_ONE", + "GROUP_THREE" + ], + "resourceDeniedAuthorities": [ + "GROUP_TWO" + ], + "resourceReaderSecurityControls": [ + "e428663f-9171-42e2-b233-d8f2cd3f54f7:mF2foUuA" + ] + } +} diff --git a/src/test/resources/auth/PeerAssocCreated.json b/src/test/resources/auth/PeerAssocCreated.json new file mode 100644 index 0000000..24dbd2b --- /dev/null +++ b/src/test/resources/auth/PeerAssocCreated.json @@ -0,0 +1,26 @@ +{ + "specversion": "1.0", + "type": "org.alfresco.event.assoc.peer.Created", + "id": "8677a369-a30d-469e-b313-e5bf1b590c8e", + "source": "/f6d21231-618e-4f12-a920-e498660c5b9d", + "time": "2020-06-10T10:36:21.291392+01:00", + "dataschema": "https://api.alfresco.com/schema/event/repo/v1/peerAssocCreated", + "datacontenttype": "application/json", + "data": { + "eventGroupId": "b23f75d0-45da-40d1-9063-eb800a4f2444", + "resource": { + "@type": "PeerAssociationResource", + "assocType": "cm:references", + "source": { + "id": "d323671c-9bd0-483e-8471-bd64cea73c09" + }, + "target": { + "id": "595c55b0-64b3-4f1b-95f8-c1cc6b3843a2" + } + }, + "resourceReaderAuthorities": [], + "resourceDeniedAuthorities": [ + "GROUP_TWO" + ] + } +} diff --git a/src/test/resources/ChildAssocCreated.json b/src/test/resources/noAuth/ChildAssocCreated.json similarity index 100% rename from src/test/resources/ChildAssocCreated.json rename to src/test/resources/noAuth/ChildAssocCreated.json diff --git a/src/test/resources/NodeCreatedEvent.json b/src/test/resources/noAuth/NodeCreatedEvent.json similarity index 100% rename from src/test/resources/NodeCreatedEvent.json rename to src/test/resources/noAuth/NodeCreatedEvent.json diff --git a/src/test/resources/NodeCreatedEventWithExtension.json b/src/test/resources/noAuth/NodeCreatedEventWithExtension.json similarity index 100% rename from src/test/resources/NodeCreatedEventWithExtension.json rename to src/test/resources/noAuth/NodeCreatedEventWithExtension.json diff --git a/src/test/resources/NodeUpdatedEvent.json b/src/test/resources/noAuth/NodeUpdatedEvent.json similarity index 100% rename from src/test/resources/NodeUpdatedEvent.json rename to src/test/resources/noAuth/NodeUpdatedEvent.json diff --git a/src/test/resources/PeerAssocCreated.json b/src/test/resources/noAuth/PeerAssocCreated.json similarity index 100% rename from src/test/resources/PeerAssocCreated.json rename to src/test/resources/noAuth/PeerAssocCreated.json