Skip to content

Commit

Permalink
Merge pull request #110 from Financial-Times/feature/UPPSF-4123-creat…
Browse files Browse the repository at this point in the history
…e-pull-notifications

Feature/uppsf 4123 create pull notifications
  • Loading branch information
martin-stanchev committed Jan 25, 2023
2 parents 447b7d2 + 96b1bdd commit 55561df
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
31 changes: 16 additions & 15 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,22 @@ Note that one policy might be used by many filters and filters might work with m
| editorialDeskFilter | Removes the `editorialDesk` field from the response unless the INTERNAL_ANALYTICS policy is present | /content, /enrichedcontent, /internalcontent |
| internalAnalyticsTagsFilter | Removes the `internalAnalyticsTags` field from the response unless the INTERNAL_ANALYTICS policy is present | /content, /enrichedcontent, /internalcontent |

| Policy | Description | Affected fields |
|------------------------------------|------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------|
| INCLUDE_RICH_CONTENT | Allows rich content (images) related fields/content to be returned in response | mainImage, bodyXML, openingXML |
| INCLUDE_IDENTIFIERS | Allows including the `identifiers` field in the response | identifiers |
| INCLUDE_COMMENTS | Allows including the `comments` field in the response | comments |
| INCLUDE_PROVENANCE | Allows including information about the provenance of the content in the response | publishReference, masterSource |
| INCLUDE_LAST_MODIFIED_DATE | Allows including the `lastModified` field in the response | lastModified |
| INCLUDE_LITE | Allows including the `lite` field in the response | lite |
| FASTFT_CONTENT_ONLY | Includes events only for FastFT branded content into notification response | * |
| EXCLUDE_FASTFT_CONTENT | Excludes events for content with FastFT brand from notification response | * |
| INTERNAL_UNSTABLE | Allows including fields considered as "unstable" for internal usage | alternativeTitles, alternativeImages, alternativeStandfirsts, openingXML, accessLevel, contains, containedIn |
| INTERNAL_ANALYTICS | Allows fields for internal analytics usage | editorialDesk |
| EXPAND_RICH_CONTENT | If present along with INCLUDE_RICH_CONTENT it allows expanding rich content related fields in the response | mainImage, embeds, alternativeImages, promotionalImage, members, leadImages, image |
| RESTRICT_NON_SYNDICATABLE_CONTENT | If present non-syndicatable content will throw a 403 Forbidden HTTP error as a response | canBeSyndicated |
| APPEND_LIVE_BLOG_NOTIFICATIONS | Allows including live blog package & live blog post content in the notifications response | * |
| Policy | Description | Affected fields |
|-----------------------------------|------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------|
| INCLUDE_RICH_CONTENT | Allows rich content (images) related fields/content to be returned in response | mainImage, bodyXML, openingXML |
| INCLUDE_IDENTIFIERS | Allows including the `identifiers` field in the response | identifiers |
| INCLUDE_COMMENTS | Allows including the `comments` field in the response | comments |
| INCLUDE_PROVENANCE | Allows including information about the provenance of the content in the response | publishReference, masterSource |
| INCLUDE_LAST_MODIFIED_DATE | Allows including the `lastModified` field in the response | lastModified |
| INCLUDE_LITE | Allows including the `lite` field in the response | lite |
| FASTFT_CONTENT_ONLY | Includes events only for FastFT branded content into notification response | * |
| EXCLUDE_FASTFT_CONTENT | Excludes events for content with FastFT brand from notification response | * |
| INTERNAL_UNSTABLE | Allows including fields considered as "unstable" for internal usage | alternativeTitles, alternativeImages, alternativeStandfirsts, openingXML, accessLevel, contains, containedIn |
| INTERNAL_ANALYTICS | Allows fields for internal analytics usage | editorialDesk |
| EXPAND_RICH_CONTENT | If present along with INCLUDE_RICH_CONTENT it allows expanding rich content related fields in the response | mainImage, embeds, alternativeImages, promotionalImage, members, leadImages, image |
| RESTRICT_NON_SYNDICATABLE_CONTENT | If present non-syndicatable content will throw a 403 Forbidden HTTP error as a response | canBeSyndicated |
| APPEND_LIVE_BLOG_NOTIFICATIONS | Allows including live blog package & live blog post content in the notifications response | * |
| ADVANCED_NOTIFICATIONS | Allows distinguishing between CREATE and UPDATE notifications in the notifications-rw response | * |

Header Handling
===============
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public enum Policy {
EXPAND_RICH_CONTENT("EXPAND_RICH_CONTENT"),
RESTRICT_NON_SYNDICATABLE_CONTENT("RESTRICT_NON_SYNDICATABLE_CONTENT"),
INTERNAL_ANALYTICS("INTERNAL_ANALYTICS"),
APPEND_LIVE_BLOG_NOTIFICATIONS("APPEND_LIVE_BLOG_NOTIFICATIONS");
APPEND_LIVE_BLOG_NOTIFICATIONS("APPEND_LIVE_BLOG_NOTIFICATIONS"),
ADVANCED_NOTIFICATIONS("ADVANCED_NOTIFICATIONS");

private final String headerValue;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ft.up.apipolicy.filters;

import static com.ft.up.apipolicy.configuration.Policy.ADVANCED_NOTIFICATIONS;
import static com.ft.up.apipolicy.configuration.Policy.APPEND_LIVE_BLOG_NOTIFICATIONS;
import static com.ft.up.apipolicy.configuration.Policy.INTERNAL_UNSTABLE;

Expand All @@ -20,6 +21,7 @@ public class NotificationsTypeFilter implements ApiFilter {
private static final String HREF_KEY = "href";
private static final String TYPE_KEY = "type";
private static final String MONITOR_KEY = "monitor";
private static final String HIDE_CREATE_EVENTS_KEY = "hideCreate";
private static final String ALL_CONTENT_TYPES = "All";
private static final String ARTICLE_CONTENT_TYPE = "Article";
private static final String LIVE_BLOG_POST_CONTENT_TYPE = "LiveBlogPost";
Expand Down Expand Up @@ -65,6 +67,7 @@ public MutableResponse processRequest(MutableRequest request, HttpPipelineChain
private void addQueryParams(MutableRequest request) {
List<String> typeParams = new ArrayList<>();
List<String> monitorParams = new ArrayList<>();
List<String> hideCreateEventsParams = new ArrayList<>();

if (request.policyIs(INTERNAL_UNSTABLE)) {
typeParams.add(ALL_CONTENT_TYPES);
Expand All @@ -79,6 +82,13 @@ private void addQueryParams(MutableRequest request) {
monitorParams.add(Boolean.FALSE.toString());
}

if (request.policyIs(ADVANCED_NOTIFICATIONS)) {
hideCreateEventsParams.add(Boolean.FALSE.toString());
} else {
hideCreateEventsParams.add(Boolean.TRUE.toString());
}

request.getQueryParameters().put(HIDE_CREATE_EVENTS_KEY, hideCreateEventsParams);
request.getQueryParameters().put(TYPE_KEY, typeParams);
request.getQueryParameters().put(MONITOR_KEY, monitorParams);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ public void testThatForNon200ResponseNoOtherInteractionHappens() {
filter.processRequest(request, chain);

verify(request).policyIs(Policy.INTERNAL_UNSTABLE);
verify(request, times(2)).getQueryParameters();
verify(request).policyIs(Policy.ADVANCED_NOTIFICATIONS);
verify(request, times(3)).getQueryParameters();
verifyNoMoreInteractions(request);
}

Expand Down

0 comments on commit 55561df

Please sign in to comment.