Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pubsub): add support for links in pubsub triggers #1235

Merged
merged 2 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,26 @@ protected Function<Trigger, Trigger> buildTrigger(PubsubEvent pubsubEvent) {
Map parameters =
payload.containsKey("parameters") ? (Map) payload.get("parameters") : new HashMap();
MessageDescription description = pubsubEvent.getContent().getMessageDescription();
return trigger ->
trigger
.atMessageDescription(
description.getSubscriptionName(), description.getPubsubSystem().toString())
.atParameters(parameters)
.atPayload(payload)
.atEventId(pubsubEvent.getEventId());
return inputTrigger -> {
Trigger trigger =
inputTrigger
.atMessageDescription(
description.getSubscriptionName(), description.getPubsubSystem().toString())
.atParameters(parameters)
.atPayload(payload)
.atEventId(pubsubEvent.getEventId());

Object linkTextObject = payload.get("linkText");
Object linkObject = payload.get("link");
if (linkTextObject instanceof String && linkObject instanceof String) {
String linkText = (String) linkTextObject;
String link = (String) linkObject;
if (StringUtils.isNotBlank(linkText) && StringUtils.isNotBlank(link)) {
trigger = trigger.withLink(link).withLinkText(linkText);
}
}
return trigger;
};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,33 @@ class PubsubEventHandlerSpec extends Specification implements RetrofitStubs {
enabledGooglePubsubTrigger.withAttributeConstraints([key: 'value']) | 1
enabledGooglePubsubTrigger.withAttributeConstraints([key: 'wrongValue']) | 0
}

@Unroll
def "sets link details if defined"() {
given:
def trigger = enabledGooglePubsubTrigger

def event = new PubsubEvent()
def description = MessageDescription.builder()
.pubsubSystem(PubsubSystem.GOOGLE)
.ackDeadlineSeconds(1)
.subscriptionName("projects/project/subscriptions/subscription")
.messagePayload(JsonOutput.toJson([key: 'value']))
.messageAttributes([key: 'value'])
.build()

when:
def content = new PubsubEvent.Content()
content.setMessageDescription(description)
event.content = content
def link = 'https://sample.com'
def linkText = 'someLinkText'
event.payload = [link: link, linkText: linkText]

def outputTrigger = eventHandler.buildTrigger(event).apply(trigger)

then:
outputTrigger.link.equals(link)
outputTrigger.linkText.equals(linkText)
}
}