Skip to content

Commit

Permalink
GH-221 wiring the new x-event-phidata header support in Adobe IO Ev…
Browse files Browse the repository at this point in the history
…ents `eventsingress` `PublishApi` (#222)

Also re-making the constants public to fix a former breaking API change
  • Loading branch information
francoisledroff authored Jun 24, 2024
1 parent 3dac968 commit 6ab542b
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 28 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/com/adobe/aio/util/feign/FeignUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public class FeignUtil {
public static final String AIO_FEIGN_RETRY_MAX_PERIOD = "AIO_FEIGN_RETRY_MAX_PERIOD";


private static final int DEFAULT_CONNECT_TIMEOUT_IN_SECONDS = 10;
private static final int DEFAULT_READ_TIMEOUT_IN_SECONDS = 60;
public static final int DEFAULT_CONNECT_TIMEOUT_IN_SECONDS = 10;
public static final int DEFAULT_READ_TIMEOUT_IN_SECONDS = 60;
public static final long DEFAULT_RETRY_PERIOD_IN_SECONDS = 1000L;
public static final int DEFAULT_MAX_ATTEMPTS = 3;
public static final long DEFAULT_MAX_PERIOD_IN_SECONDS = 4L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ CloudEvent publishCloudEvent(String providerId, String eventCode, String data)
throws JsonProcessingException;
CloudEvent publishCloudEvent(String providerId, String eventCode, String eventId, String data)
throws JsonProcessingException;
CloudEvent publishCloudEvent(Boolean isPhiData, String providerId, String eventCode, String eventId, JsonNode data);

void publishRawEvent(String providerId, String eventCode, String rawEvent);

void publishRawEvent(Boolean isPhiData, String providerId, String eventCode, String eventId, String rawEvent);

static Builder builder() {
return new Builder();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,37 @@ public interface PublishApi {
* publish a Cloud Event Payload
*
* @param body your CloudEvent Input Model
* @param isPhiData true if the event contains PHI Data
*/
@RequestLine("POST")
@Headers({"Content-Type: application/cloudevents+json"})
void publishCloudEvent(CloudEvent body);
@Headers({
"Content-Type: application/cloudevents+json",
"x-event-phidata: {isPhiData}"})
void publishCloudEvent(
@Param("isPhiData") Boolean isPhiData,
CloudEvent body);

/**
* publish a Raw Event Json Payload
* @param isPhiData true if the event contains PHI Data
* @param eventCode the Adobe I/O EventMetadata eventCode associated with the Event
* @param providerId the Adobe I/O EventMetadata ProviderId associated with the Event
* @param eventId the eventId you want to assign to this the Event (mandatory if isPhiData is true)
* @param rawEvent the Raw Event Json Payload to publish
*/
@RequestLine("POST")
@Headers({
"Content-Type: application/json",
"x-adobe-event-provider-id: {providerId}",
"x-adobe-event-code: {eventCode}"
"Content-Type: application/json",
"x-event-phidata: {isPhiData}",
"x-event-id: {eventId}",
"x-adobe-event-provider-id: {providerId}",
"x-adobe-event-code: {eventCode}"
})
void publishRawEvent(
@Param("providerId") String providerId,
@Param("eventCode") String eventCode,
JsonNode rawEvent);
@Param("isPhiData") Boolean isPhiData,
@Param("providerId") String providerId,
@Param("eventCode") String eventCode,
@Param("eventId") String eventId,
JsonNode rawEvent);

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,37 @@ public CloudEvent publishCloudEvent(String providerId, String eventCode,

@Override
public CloudEvent publishCloudEvent(String providerId, String eventCode, String eventId,
String data) throws JsonProcessingException {
return publishCloudEvent(providerId, eventCode, eventId, JacksonUtil.getJsonNode(data));
String cloudEventData) throws JsonProcessingException {
return publishCloudEvent(providerId, eventCode, eventId, JacksonUtil.getJsonNode(cloudEventData));
}

@Override
public CloudEvent publishCloudEvent(String providerId, String eventCode, String eventId,
JsonNode data) {
JsonNode cloudEventData) {
return publishCloudEvent(false, providerId, eventCode, eventId, cloudEventData);
}

@Override
public CloudEvent publishCloudEvent(Boolean isPhiData, String providerId, String eventCode, String eventId,
JsonNode cloudEventData) {
CloudEvent inputModel = CloudEvent.builder()
.providerId(providerId).eventCode(eventCode).eventId(eventId)
.data(data).build();
publishApi.publishCloudEvent(inputModel);
.data(cloudEventData).build();
publishApi.publishCloudEvent(isPhiData, inputModel);
return inputModel;
}

@Override
public void publishRawEvent(String providerId, String eventCode, String rawEvent) {
publishApi.publishRawEvent(providerId, eventCode, getJsonNode(rawEvent));
publishApi.publishRawEvent(false, providerId, eventCode, null, getJsonNode(rawEvent));
}

@Override
public void publishRawEvent(Boolean isPhiData, String providerId, String eventCode, String eventId, String rawEvent) {
if (isPhiData !=null && isPhiData && StringUtils.isEmpty(eventId)) {
throw new AIOException("Cannot publish PHI data without an eventId");
}
publishApi.publishRawEvent(isPhiData, providerId, eventCode, eventId, getJsonNode(rawEvent));
}

private static JsonNode getJsonNode(String jsonPayload) {
Expand Down
6 changes: 4 additions & 2 deletions events_test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static org.junit.jupiter.api.Assertions.fail;

import com.adobe.aio.event.publish.model.CloudEvent;
import com.adobe.aio.util.JacksonUtil;
import com.adobe.aio.util.WorkspaceUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import java.util.UUID;
Expand All @@ -37,15 +38,15 @@ public PublishServiceTester(){
.build();
}

public String publishCloudEvent(String providerId, String eventCode) {
public String publishCloudEvent(Boolean isPhiData, String providerId, String eventCode) {
String eventId = UUID.randomUUID().toString();
return this.publishCloudEvent(providerId, eventCode, eventId, getDummyDataNode(eventId));
return this.publishCloudEvent(isPhiData, providerId, eventCode, eventId, getDummyDataNode(eventId));
}

public String publishCloudEvent(String providerId, String eventCode, String eventId, String data) {
public String publishCloudEvent(Boolean isPhiData, String providerId, String eventCode, String eventId, String data) {
try {
CloudEvent cloudEvent = publishService.publishCloudEvent(
providerId, eventCode, eventId, data);
CloudEvent cloudEvent = publishService.publishCloudEvent(isPhiData,
providerId, eventCode, eventId, JacksonUtil.getJsonNode(data));
logger.info("Published CloudEvent: {}", cloudEvent);
assertEquals(eventId, cloudEvent.getId());
assertEquals(CloudEvent.SOURCE_URN_PREFIX + providerId, cloudEvent.getSource());
Expand All @@ -60,6 +61,12 @@ public String publishCloudEvent(String providerId, String eventCode, String even
}
}

public String publishRawEvent(Boolean isPhiData, String providerId, String eventCode, String eventId) {
publishService.publishRawEvent(isPhiData, providerId, eventCode, eventId, getDummyDataNode(eventId));
logger.info("Published Raw Event: {}", getDummyDataNode(eventId));
return eventId;
}

public String publishRawEvent(String providerId, String eventCode) {
String eventId = UUID.randomUUID().toString();
publishService.publishRawEvent(providerId, eventCode, getDummyDataNode(eventId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void testJournalPolling()
TEST_REGISTRATION_NAME, providerId, TEST_EVENT_CODE);
registrationId = registration.getRegistrationId();

String cloudEventId = publishServiceTester.publishCloudEvent(providerId, TEST_EVENT_CODE);
String cloudEventId = publishServiceTester.publishCloudEvent(false, providerId, TEST_EVENT_CODE);
boolean wasCloudEventPolled = pollJournalForEvent(
registration.getJournalUrl().getHref(), cloudEventId, isEventIdTheCloudEventId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
import static com.adobe.aio.event.management.ProviderServiceIntegrationTest.TEST_EVENT_CODE;
import static com.adobe.aio.event.management.ProviderServiceIntegrationTest.TEST_EVENT_PROVIDER_LABEL;
import static com.adobe.aio.event.management.RegistrationServiceIntegrationTest.TEST_REGISTRATION_NAME;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.*;

import com.adobe.aio.event.management.ProviderServiceTester;
import com.adobe.aio.event.management.RegistrationServiceTester;
import com.adobe.aio.exception.AIOException;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -49,8 +48,16 @@ public void publishEventTest() {
registrationId = registrationServiceTester.createOrUpdateJournalRegistration(
TEST_REGISTRATION_NAME, providerId, TEST_EVENT_CODE).getRegistrationId();

assertNotNull(publishCloudEvent(providerId, TEST_EVENT_CODE));
assertNotNull(publishCloudEvent(null, providerId, TEST_EVENT_CODE));
assertNotNull(publishCloudEvent(false, providerId, TEST_EVENT_CODE));
assertNotNull(publishCloudEvent(true, providerId, TEST_EVENT_CODE));
assertNotNull(publishRawEvent(providerId, TEST_EVENT_CODE));
assertNotNull(publishRawEvent(Boolean.TRUE, providerId, TEST_EVENT_CODE, "someEventId"));

final String finalProviderId = providerId;
Exception ex = assertThrows(AIOException.class,() -> publishRawEvent(Boolean.TRUE, finalProviderId, TEST_EVENT_CODE, null));
assertEquals("Cannot publish PHI data without an eventId", ex.getMessage());

} catch (Exception e) {
logger.error(e.getMessage(), e);
fail(e.getMessage());
Expand Down

0 comments on commit 6ab542b

Please sign in to comment.