Skip to content

Commit

Permalink
Merge branch 'release/0.44.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
AudreyKj committed May 17, 2022
2 parents df65b71 + fd715f8 commit 71b35d5
Show file tree
Hide file tree
Showing 278 changed files with 4,977 additions and 1,305 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.43.0
0.44.0
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public ResponseEntity<?> subscribe(@RequestBody @Valid WebhookSubscribePayload p
final UUID id = Optional.ofNullable(payload.getId()).orElse(UUID.randomUUID());
final Webhook webhook = Webhook.newBuilder()
.setId(id.toString())
.setName(payload.getName())
.setEvents(payload.getEvents().stream().map(EventType::getEventType).collect(Collectors.toList()))
.setEndpoint(payload.getUrl().toString())
.setStatus(Status.Subscribed)
Expand Down Expand Up @@ -78,13 +79,13 @@ public ResponseEntity<?> update(@RequestBody @Valid WebhookUpdatePayload payload
if (webhook == null) {
return ResponseEntity.notFound().build();
}
if (webhook.getStatus().equals(Status.Unsubscribed)) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(fromWebhook(webhook));
}

if (payload.getUrl() != null) {
webhook.setEndpoint(payload.getUrl().toString());
}
if (payload.getName() != null) {
webhook.setName(payload.getName().toString());
}
if (payload.getEvents() != null) {
webhook.setEvents(payload.getEvents().stream().map(EventType::getEventType).collect(Collectors.toList()));
}
Expand All @@ -94,6 +95,14 @@ public ResponseEntity<?> update(@RequestBody @Valid WebhookUpdatePayload payload
if (payload.getSignatureKey() != null) {
webhook.setSignKey(payload.getSignatureKey());
}
if (payload.getStatus() != null) {
if (Status.Subscribed.toString().equals(payload.getStatus().toString())) {
webhook.setStatus(Status.Subscribed);
}
if (Status.Unsubscribed.toString().equals(payload.getStatus().toString())) {
webhook.setStatus(Status.Unsubscribed);
}
}

try {
stores.storeWebhook(webhook);
Expand Down Expand Up @@ -138,14 +147,14 @@ public ResponseEntity<WebhookResponsePayload> webhookInfo(@RequestBody @Valid We
@PostMapping("/webhooks.list")
public ResponseEntity<WebhookListResponsePayload> webhookList() {
final List<WebhookListPayload> webhooks = stores.getWebhooks().stream()
.filter(((webhook) -> webhook.getStatus().equals(Status.Subscribed)))
.map(this::fromWebhookList).collect(Collectors.toList());
return ResponseEntity.status(HttpStatus.OK).body(new WebhookListResponsePayload(webhooks));
}

private WebhookResponsePayload fromWebhook(Webhook webhook) {
return WebhookResponsePayload.builder()
.id(webhook.getId())
.name(webhook.getName())
.events(webhook.getEvents())
.headers(webhook.getHeaders())
.status(webhook.getStatus().toString())
Expand All @@ -156,8 +165,10 @@ private WebhookResponsePayload fromWebhook(Webhook webhook) {
private WebhookListPayload fromWebhookList(Webhook webhook) {
return WebhookListPayload.builder()
.id(webhook.getId())
.name(webhook.getName())
.events(webhook.getEvents())
.headers(webhook.getHeaders())
.status(webhook.getStatus().toString())
.url(webhook.getEndpoint())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ public class WebhookListPayload {
private String url;
private Map<String, String> headers;
private List<String> events;
private String status;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class WebhookSubscribePayload {
private UUID id;
@NotNull
private URL url;
private String name;
private Map<String, String> headers = new HashMap<>();
private List<EventType> events = new ArrayList<>();
private String signatureKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
@AllArgsConstructor
public class WebhookUpdatePayload {
private URL url;
private String name;
private Map<String, String> headers = new HashMap<>();
private List<EventType> events = new ArrayList<>();
private String signatureKey;
private String status;
@NotNull
private UUID id;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public ClientConfigController(ServiceDiscovery serviceDiscovery, PrincipalAccess
this.tagConfig = new ObjectMapper().readTree(tagConfigResource);
try (InputStream is = version.getInputStream()) {
clusterVersion = StreamUtils.copyToString(is, StandardCharsets.UTF_8);
;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,16 @@ public void canManageWebhook() throws Exception {
webTestHelper.post("/webhooks.info", infoPayload).andExpect(status().isNotFound());

final String url = "http://example.org/webhook";
final String name = "webhook name";
final String xAuthHeader = "auth token";
final EventType subscribeEvent = EventType.MESSAGE_CREATED;
final EventType newSubscribeEvent = EventType.MESSAGE_UPDATED;

final String subscribePayload = String.format("{\"id\":\"%s\",\"url\":\"%s\",\"headers\":{\"X-Auth\":\"%s\"},\"events\":[\"%s\"]}",
webhookId, url, xAuthHeader, subscribeEvent.getEventType());
final String subscribePayload = String.format("{\"id\":\"%s\",\"name\":\"%s\",\"url\":\"%s\",\"headers\":{\"X-Auth\":\"%s\"},\"events\":[\"%s\"]}",
webhookId, name, url, xAuthHeader, subscribeEvent.getEventType());

final String updatePayload = String.format("{\"id\":\"%s\",\"url\":\"%s\",\"headers\":{\"X-Auth\":\"%s\"},\"events\":[\"%s\", \"%s\"]}",
webhookId, url, xAuthHeader, subscribeEvent.getEventType(), newSubscribeEvent.getEventType());
final String updatePayload = String.format("{\"id\":\"%s\",\"name\":\"%s\",\"url\":\"%s\",\"headers\":{\"X-Auth\":\"%s\"},\"events\":[\"%s\", \"%s\"]}",
webhookId, name, url, xAuthHeader, subscribeEvent.getEventType(), newSubscribeEvent.getEventType());

when(serviceDiscovery.getComponent(Mockito.anyString())).thenCallRealMethod();

Expand All @@ -113,12 +114,14 @@ public void canManageWebhook() throws Exception {
webTestHelper.post("/webhooks.subscribe", subscribePayload)
.andExpect(status().isOk())
.andExpect(jsonPath("$.id", equalTo(webhookId)))
.andExpect(jsonPath("$.name", equalTo(name)))
.andExpect(jsonPath("$.url", equalTo(url)))
.andExpect(jsonPath("$.headers['X-Auth']", equalTo(xAuthHeader)));

retryOnException(() -> webTestHelper.post("/webhooks.update", updatePayload)
.andExpect(status().isOk())
.andExpect(jsonPath("$.id", equalTo(webhookId)))
.andExpect(jsonPath("$.name", equalTo(name)))
.andExpect(jsonPath("$.url", equalTo(url)))
.andExpect(jsonPath("$.headers['X-Auth']", equalTo(xAuthHeader)))
.andExpect(jsonPath("$.events", hasSize(2))),
Expand All @@ -128,6 +131,7 @@ public void canManageWebhook() throws Exception {
retryOnException(() -> webTestHelper.post("/webhooks.info", infoPayload)
.andExpect(status().isOk())
.andExpect(jsonPath("$.id", equalTo(webhookId)))
.andExpect(jsonPath("$.name", equalTo(name)))
.andExpect(jsonPath("$.url", equalTo(url)))
.andExpect(jsonPath("$.headers['X-Auth']", equalTo(xAuthHeader))),
"Webhook was not stored"
Expand All @@ -145,6 +149,7 @@ public void canListWebhooks() throws Exception {
new ProducerRecord<>(Topics.applicationCommunicationWebhooks.name(), UUID.randomUUID().toString(),
Webhook.newBuilder()
.setEndpoint("http://endpoint.com/webhook")
.setName("webhook name")
.setId(UUID.randomUUID().toString())
.setStatus(Status.Subscribed)
.setSubscribedAt(Instant.now().toEpochMilli())
Expand All @@ -153,6 +158,7 @@ public void canListWebhooks() throws Exception {
new ProducerRecord<>(Topics.applicationCommunicationWebhooks.name(), UUID.randomUUID().toString(),
Webhook.newBuilder()
.setEndpoint("http://endpoint.com/webhook-2")
.setName("webhook name 2")
.setId(UUID.randomUUID().toString())
.setStatus(Status.Subscribed)
.setSubscribedAt(Instant.now().toEpochMilli())
Expand All @@ -161,6 +167,7 @@ public void canListWebhooks() throws Exception {
new ProducerRecord<>(Topics.applicationCommunicationWebhooks.name(), UUID.randomUUID().toString(),
Webhook.newBuilder()
.setEndpoint("http://endpoint.com/webhook-2")
.setName("webhook name 2")
.setId(UUID.randomUUID().toString())
.setStatus(Status.Unsubscribed)
.setSubscribedAt(Instant.now().toEpochMilli())
Expand All @@ -170,7 +177,7 @@ public void canListWebhooks() throws Exception {

retryOnException(() -> webTestHelper.post("/webhooks.list")
.andExpect(status().isOk())
.andExpect(jsonPath("$.data", hasSize(lessThanOrEqualTo(2)))),
.andExpect(jsonPath("$.data", hasSize(lessThanOrEqualTo(4)))),
"list did not return all results"
);
}
Expand Down
1 change: 1 addition & 0 deletions backend/api/contacts/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ load("//tools/build:container_release.bzl", "container_release")
app_deps = [
"//backend:base_app",
"//backend/model/conversation",
"//backend/model/contacts",
"//backend/model/metadata",
"//backend/model/message",
"//lib/java/uuid",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package co.airy.core.contacts;

import co.airy.avro.communication.Metadata;
import co.airy.core.contacts.dto.Contact;
import co.airy.model.contacts.Contact;
import co.airy.core.contacts.payload.ContactInfoRequestPayload;
import co.airy.core.contacts.payload.ContactResponsePayload;
import co.airy.core.contacts.payload.ContactWithMergeHistoryResponsePayload;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import co.airy.avro.communication.Message;
import co.airy.avro.communication.Metadata;
import co.airy.core.contacts.dto.Contact;
import co.airy.core.contacts.dto.ConversationContact;
import co.airy.model.contacts.Contact;
import co.airy.model.contacts.ConversationContact;
import co.airy.kafka.schema.application.ApplicationCommunicationContacts;
import co.airy.kafka.schema.application.ApplicationCommunicationMessages;
import co.airy.kafka.schema.application.ApplicationCommunicationMetadata;
Expand Down Expand Up @@ -35,8 +35,8 @@
import java.util.Map;
import java.util.UUID;

import static co.airy.core.contacts.MetadataRepository.newContactMetadata;
import static co.airy.core.contacts.dto.Contact.MetadataKeys.CONVERSATIONS;
import static co.airy.model.contacts.MetadataRepository.newContactMetadata;
import static co.airy.model.contacts.Contact.MetadataKeys.CONVERSATIONS;
import static co.airy.model.metadata.MetadataKeys.ConversationKeys.CONTACT;
import static co.airy.model.metadata.MetadataRepository.getId;
import static co.airy.model.metadata.MetadataRepository.getSubject;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package co.airy.core.contacts.payload;

import co.airy.core.contacts.dto.Contact;
import co.airy.model.contacts.Contact;
import com.fasterxml.jackson.databind.JsonNode;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package co.airy.core.contacts.payload;

import co.airy.core.contacts.dto.Contact;
import co.airy.model.contacts.Contact;

import com.fasterxml.jackson.databind.JsonNode;
import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package co.airy.core.contacts.payload;

import co.airy.core.contacts.dto.Contact;
import co.airy.model.contacts.Contact;
import com.fasterxml.jackson.databind.JsonNode;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package co.airy.core.contacts.payload;

import co.airy.core.contacts.dto.Contact;
import co.airy.model.contacts.Contact;
import com.fasterxml.jackson.databind.JsonNode;
import lombok.Data;
import lombok.NoArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import co.airy.spring.core.AirySpringBootApplication;
import co.airy.spring.test.WebTestHelper;
import co.airy.core.contacts.dto.Contact;
import co.airy.model.contacts.Contact;
import co.airy.core.contacts.payload.DeleteContactPayload;
import co.airy.core.contacts.util.TestContact;
import co.airy.core.contacts.util.Topics;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package co.airy.core.contacts;

import co.airy.core.contacts.dto.Contact;
import co.airy.model.contacts.Contact;
import co.airy.core.contacts.util.TestContact;
import co.airy.core.contacts.util.Topics;
import co.airy.kafka.test.KafkaTestHelper;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package co.airy.core.contacts;

import co.airy.core.contacts.dto.Contact;
import co.airy.model.contacts.Contact;
import co.airy.core.contacts.util.TestContact;
import co.airy.core.contacts.util.Topics;
import co.airy.kafka.test.KafkaTestHelper;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package co.airy.core.contacts.util;

import co.airy.core.contacts.dto.Contact;
import co.airy.model.contacts.Contact;
import co.airy.spring.test.WebTestHelper;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.JsonNode;
Expand Down
8 changes: 8 additions & 0 deletions backend/avro/webhook.avsc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
"name": "id",
"type": "string"
},
{
"name": "name",
"type": [
"null",
"string"
],
"default": null
},
{
"name": "events",
"type": {
Expand Down
17 changes: 17 additions & 0 deletions backend/model/contacts/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
load("@com_github_airyhq_bazel_tools//lint:buildifier.bzl", "check_pkg")
load("//tools/build:java_library.bzl", "custom_java_library")

custom_java_library(
name = "contacts",
srcs = glob(["src/main/java/co/airy/model/contacts/**/*.java"]),
visibility = ["//visibility:public"],
deps = [
"//:jackson",
"//:lombok",
"//backend/model/conversation",
"//backend/model/metadata",
"//lib/java/log",
],
)

check_pkg(name = "buildifier")
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.airy.core.contacts.dto;
package co.airy.model.contacts;

import co.airy.avro.communication.Metadata;
import co.airy.log.AiryLoggerFactory;
Expand Down Expand Up @@ -27,19 +27,19 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static co.airy.core.contacts.MetadataRepository.newContactMetadata;
import static co.airy.core.contacts.dto.Contact.MetadataKeys.ADDRESS;
import static co.airy.core.contacts.dto.Contact.MetadataKeys.AVATAR_URL;
import static co.airy.core.contacts.dto.Contact.MetadataKeys.CONVERSATIONS;
import static co.airy.core.contacts.dto.Contact.MetadataKeys.CREATED_AT;
import static co.airy.core.contacts.dto.Contact.MetadataKeys.DISPLAY_NAME;
import static co.airy.core.contacts.dto.Contact.MetadataKeys.GENDER;
import static co.airy.core.contacts.dto.Contact.MetadataKeys.LOCALE;
import static co.airy.core.contacts.dto.Contact.MetadataKeys.ORGANIZATION_NAME;
import static co.airy.core.contacts.dto.Contact.MetadataKeys.MERGE_HISTORY;
import static co.airy.core.contacts.dto.Contact.MetadataKeys.TIMEZONE;
import static co.airy.core.contacts.dto.Contact.MetadataKeys.TITLE;
import static co.airy.core.contacts.dto.Contact.MetadataKeys.VIA;
import static co.airy.model.contacts.MetadataRepository.newContactMetadata;
import static co.airy.model.contacts.Contact.MetadataKeys.ADDRESS;
import static co.airy.model.contacts.Contact.MetadataKeys.AVATAR_URL;
import static co.airy.model.contacts.Contact.MetadataKeys.CONVERSATIONS;
import static co.airy.model.contacts.Contact.MetadataKeys.CREATED_AT;
import static co.airy.model.contacts.Contact.MetadataKeys.DISPLAY_NAME;
import static co.airy.model.contacts.Contact.MetadataKeys.GENDER;
import static co.airy.model.contacts.Contact.MetadataKeys.LOCALE;
import static co.airy.model.contacts.Contact.MetadataKeys.ORGANIZATION_NAME;
import static co.airy.model.contacts.Contact.MetadataKeys.MERGE_HISTORY;
import static co.airy.model.contacts.Contact.MetadataKeys.TIMEZONE;
import static co.airy.model.contacts.Contact.MetadataKeys.TITLE;
import static co.airy.model.contacts.Contact.MetadataKeys.VIA;
import static co.airy.model.metadata.MetadataRepository.getSubject;
import static java.util.stream.Collectors.toMap;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.airy.core.contacts.dto;
package co.airy.model.contacts;

import co.airy.model.conversation.Conversation;
import co.airy.model.metadata.dto.MetadataMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.airy.core.contacts;
package co.airy.model.contacts;

import co.airy.avro.communication.Metadata;
import co.airy.model.metadata.Subject;
Expand Down
1 change: 1 addition & 0 deletions backend/sources/facebook/events-router/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ load("//tools/build:container_release.bzl", "container_release")

app_deps = [
"//backend:base_app",
"//:springboot_actuator",
"//backend/model/channel",
"//backend/model/message",
"//backend/model/metadata",
Expand Down
Loading

0 comments on commit 71b35d5

Please sign in to comment.