Skip to content
This repository has been archived by the owner on Jan 17, 2022. It is now read-only.

Commit

Permalink
Merge pull request #57 from Financial-Times/feature/canonical-web-url
Browse files Browse the repository at this point in the history
Add canonicalWebUrl
  • Loading branch information
Mihai Sorin Moisa committed May 3, 2018
2 parents 5dc7d6f + a60e26d commit cb7b62f
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 74 deletions.
3 changes: 2 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ You can find an example of a transformed article below.
"enabled": true
},
"copyright": null,
"webUrl": null,
"webUrl": "https://www.ft.com/content/59b2f3b4-69c2-11e6-a0b1-d87a9fea034f",
"canonicalWebUrl": "https://www.ft.com/content/59b2f3b4-69c2-11e6-a0b1-d87a9fea034f",
"publishReference": "tid_dn4kzqpoxf",
"lastModified": "2016-08-25T06:06:23.532Z",
"canBeSyndicated": "yes",
Expand Down
2 changes: 2 additions & 0 deletions methode-article-mapper.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ transactionIdSource: fromTransaction
transactionIdProperty: publishReference

apiHost: "api.ft.com"
canonicalWebUrlTemplate: "https://www.ft.com/content/%s"
webUrlTemplate: "https://www.ft.com/content/%s"

appInfo:
systemCode: "up-mam"
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<xmlunit.version>1.5</xmlunit.version>
<wiremock.version>1.40</wiremock.version>
<uuid-utils.version>1.0.2</uuid-utils.version>
<content-model.version>0.5.1</content-model.version>
<content-model.version>0.6.0-rj-canonical-web-url-rc1</content-model.version>
<!-- Plugins -->
<findbugs.version>2.5.2</findbugs.version>
<checkstyle.version>2.10</checkstyle.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ private EomFileProcessor configureEomFileProcessorForContentStore(
new Html5SelfClosingTagBodyProcessor(),
processConfigurationBrands(configuration.getBrandsConfiguration()),
configuration.getTxIdPropertyName(),
configuration.getApiHost());
configuration.getApiHost(),
configuration.getWebUrlTemplate(),
configuration.getCanonicalWebUrlTemplate());
}

private void registerHealthChecks(Environment environment, List<AdvancedHealthCheck> advancedHealthChecks) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class MethodeArticleMapperConfiguration extends Configuration implements
private final PropertySource txIdSource;
private final String txIdPropertyName;
private final String apiHost;
private final String webUrlTemplate;
private final String canonicalWebUrlTemplate;
private final AppInfo appInfo;
@JsonProperty
private final GTGConfig gtgConfig= new GTGConfig();
Expand All @@ -52,6 +54,8 @@ public MethodeArticleMapperConfiguration(@JsonProperty("messagingEndpointEnabled
@JsonProperty("transactionIdSource") PropertySource txIdSource,
@JsonProperty("transactionIdProperty") String txIdPropertyName,
@JsonProperty("apiHost") String apiHost,
@JsonProperty("webUrlTemplate") String webUrlTemplate,
@JsonProperty("canonicalWebUrlTemplate") String canonicalWebUrlTemplate,
@JsonProperty("appInfo") AppInfo appInfo) {

if ((documentStoreApiEnabled == null) || documentStoreApiEnabled.booleanValue()) {
Expand Down Expand Up @@ -80,6 +84,8 @@ public MethodeArticleMapperConfiguration(@JsonProperty("messagingEndpointEnabled
this.txIdSource = txIdSource;
this.txIdPropertyName = txIdPropertyName;
this.apiHost = apiHost;
this.webUrlTemplate = webUrlTemplate;
this.canonicalWebUrlTemplate = canonicalWebUrlTemplate;
this.appInfo = appInfo;
}

Expand Down Expand Up @@ -150,6 +156,16 @@ public String getApiHost() {
return apiHost;
}

@NotNull
public String getCanonicalWebUrlTemplate() {
return canonicalWebUrlTemplate;
}

@NotNull
public String getWebUrlTemplate() {
return webUrlTemplate;
}

@Override
public AppInfo getAppInfo() {
return appInfo;
Expand Down
24 changes: 4 additions & 20 deletions src/main/java/com/ft/methodearticlemapper/model/EomFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.net.URI;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
Expand Down Expand Up @@ -33,8 +32,7 @@ public class EomFile {
private final String workflowStatus;
private final String systemAttributes;
private final String usageTickets;
private final URI webUrl;


private final Map<String,String> additionalProperties = new LinkedHashMap<>();

public static void setAdditionalMappings(Map<String,String> additionalProperties) {
Expand All @@ -47,16 +45,14 @@ public EomFile(@JsonProperty("uuid") String uuid,
@JsonProperty("attributes") String attributes,
@JsonProperty("workflowStatus") String workflowStatus,
@JsonProperty("systemAttributes") String systemAttributes,
@JsonProperty("usageTickets") String usageTickets,
@JsonProperty("webUrl") URI webUrl) {
@JsonProperty("usageTickets") String usageTickets) {
this.uuid = uuid;
this.type = type;
this.value = bytes;
this.attributes = attributes;
this.workflowStatus = workflowStatus;
this.systemAttributes = systemAttributes;
this.usageTickets = usageTickets;
this.webUrl = webUrl;
}

public String getUuid() {
Expand Down Expand Up @@ -88,11 +84,6 @@ public String getUsageTickets() {
return usageTickets;
}


public URI getWebUrl() {
return webUrl;
}

@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
String mappedName = ADDITIONAL_PROPERTY_MAPPINGS.get(name);
Expand All @@ -114,7 +105,6 @@ public static class Builder {
private String workflowStatus;
private String systemAttributes;
private String usageTickets;
private URI webUrl;

public Builder withUuid(String uuid) {
this.uuid = uuid;
Expand Down Expand Up @@ -152,24 +142,18 @@ public Builder withUsageTickets(String usageTickets) {
return this;
}

public Builder withWebUrl(URI webUrl) {
this.webUrl = webUrl;
return this;
}

public Builder withValuesFrom(EomFile eomFile) {
return withUuid(eomFile.getUuid())
.withType(eomFile.getType())
.withValue(eomFile.getValue())
.withAttributes(eomFile.getAttributes())
.withWorkflowStatus(eomFile.getWorkflowStatus())
.withSystemAttributes(eomFile.getSystemAttributes())
.withUsageTickets(eomFile.getUsageTickets())
.withWebUrl(eomFile.getWebUrl());
.withUsageTickets(eomFile.getUsageTickets());
}

public EomFile build() {
return new EomFile(uuid, type, value, attributes, workflowStatus, systemAttributes, usageTickets, webUrl);
return new EomFile(uuid, type, value, attributes, workflowStatus, systemAttributes, usageTickets);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.net.URI;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -92,6 +93,8 @@ interface Type {
private final BodyProcessor htmlFieldProcessor;
private final String refFieldName;
private final String apiHost;
private final String webUrlTemplate;
private final String canonicalWebUrlTemplate;
private final Map<ContentSource, Brand> contentSourceBrandMap;

public EomFileProcessor(final EnumSet<TransformationMode> supportedModes,
Expand All @@ -100,14 +103,18 @@ public EomFileProcessor(final EnumSet<TransformationMode> supportedModes,
final BodyProcessor htmlFieldProcessor,
final Map<ContentSource, Brand> contentSourceBrandMap,
final String refFieldName,
final String apiHost) {
final String apiHost,
final String webUrlTemplate,
final String canonicalWebUrlTemplate) {
this.supportedModes = supportedModes;
this.bodyTransformer = bodyTransformer;
this.bylineTransformer = bylineTransformer;
this.htmlFieldProcessor = htmlFieldProcessor;
this.contentSourceBrandMap = contentSourceBrandMap;
this.refFieldName = refFieldName;
this.apiHost = apiHost;
this.webUrlTemplate = webUrlTemplate;
this.canonicalWebUrlTemplate = canonicalWebUrlTemplate;
}

private static Date toDate(String dateString, String format) {
Expand Down Expand Up @@ -189,6 +196,8 @@ private Content transformEomFileToContent(UUID uuid, ParsedEomFile eomFile, Tran
final AlternativeStandfirsts alternativeStandfirsts = buildAlternativeStandfirsts(xpath, value);

final String workFolder = xpath.evaluate(EomFile.WORK_FOLDER_SYSTEM_ATTRIBUTE_XPATH, eomFile.getSystemAttributes());
final URI webUrl = URI.create(String.format(this.webUrlTemplate, uuid));
final URI canonicalWebUrl = URI.create(String.format(this.canonicalWebUrlTemplate, uuid));

return Content.builder()
.withUuid(uuid)
Expand All @@ -204,7 +213,6 @@ private Content transformEomFileToContent(UUID uuid, ParsedEomFile eomFile, Tran
.withIdentifiers(ImmutableSortedSet.of(new Identifier(METHODE, uuid.toString())))
.withComments(Comments.builder().withEnabled(discussionEnabled).build())
.withStandout(buildStandoutSection(xpath, attributes))
.withWebUrl(eomFile.getWebUrl())
.withTransactionId(refFieldName, transactionId)
.withLastModified(lastModified)
.withCanBeSyndicated(canBeSyndicated)
Expand All @@ -216,6 +224,8 @@ private Content transformEomFileToContent(UUID uuid, ParsedEomFile eomFile, Tran
.withCanBeDistributed(canBeDistributed)
.withAlternativeStandfirsts(alternativeStandfirsts)
.withEditorialDesk(workFolder)
.withWebUrl(webUrl)
.withCanonicalWebUrl(canonicalWebUrl)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.ft.methodearticlemapper.methode.ContentSource;
import org.w3c.dom.Document;

import java.net.URI;
import java.util.UUID;

public class ParsedEomFile {
Expand All @@ -12,18 +11,16 @@ public class ParsedEomFile {
private final Document systemAttributes;
private final Document value;
private final String body;
private final URI webUrl;
private ContentSource contentSource;

public ParsedEomFile(UUID uuid, Document value, String body, Document attributesDocument,
Document systemAttributes, URI webUrl,
Document systemAttributes,
ContentSource contentSource) {
this.uuid = uuid;
this.value = value;
this.body = body;
this.attributesDocument = attributesDocument;
this.systemAttributes = systemAttributes;
this.webUrl = webUrl;
this.contentSource = contentSource;
}

Expand All @@ -47,10 +44,6 @@ public Document getSystemAttributes() {
return systemAttributes;
}

public URI getWebUrl() {
return webUrl;
}

public ContentSource getContentSource() {
return contentSource;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public final ParsedEomFile getEligibleContentForPublishing()
checkBody();

return new ParsedEomFile(uuid, eomFileDocument, rawBody,
attributesDocument, systemAttributesDocument, eomFile.getWebUrl(), contentSource);
attributesDocument, systemAttributesDocument, contentSource);
}

public final ParsedEomFile getEligibleContentForPreview()
Expand All @@ -166,7 +166,7 @@ public final ParsedEomFile getEligibleContentForPreview()
ContentSource contentSource = processSourceForPreview();

return new ParsedEomFile(uuid, eomFileDocument, rawBody,
attributesDocument, systemAttributesDocument ,eomFile.getWebUrl(), contentSource);
attributesDocument, systemAttributesDocument, contentSource);
}

private final void parseEomFile()
Expand Down
11 changes: 3 additions & 8 deletions src/test/java/com/ft/methodearticlemapper/model/EomFileTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.ft.methodearticlemapper.model;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;

import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -54,7 +53,6 @@ public void testEomFileWithKnownPropertiesOnly() throws IOException {
assertThat(actual.getSystemAttributes(), equalTo(SYS_ATTRS));
assertThat(actual.getWorkflowStatus(), equalTo(WEB_READY));
assertThat(actual.getUsageTickets(), equalTo(TICKETS));
assertThat(actual.getWebUrl(), nullValue());
assertThat(actual.getAdditionalProperties(), equalTo(Collections.emptyMap()));
}

Expand Down Expand Up @@ -86,8 +84,7 @@ public void thatAdditionalPropertiesAreDeserialized() throws IOException {
assertThat(actual.getSystemAttributes(), equalTo(SYS_ATTRS));
assertThat(actual.getWorkflowStatus(), equalTo(WEB_READY));
assertThat(actual.getUsageTickets(), equalTo(TICKETS));
assertThat(actual.getWebUrl(), nullValue());


Map<String,String> expectedAdditionalProperties = new HashMap<>();
expectedAdditionalProperties.put("lastModified", lastModified);
expectedAdditionalProperties.put("publishReference", publishReference);
Expand Down Expand Up @@ -123,8 +120,7 @@ public void thatUnsupportedPropertiesAreIgnored() throws IOException {
assertThat(actual.getSystemAttributes(), equalTo(SYS_ATTRS));
assertThat(actual.getWorkflowStatus(), equalTo(WEB_READY));
assertThat(actual.getUsageTickets(), equalTo(TICKETS));
assertThat(actual.getWebUrl(), nullValue());


Map<String,String> expectedAdditionalProperties = new HashMap<>();
expectedAdditionalProperties.put("lastModified", lastModified);
expectedAdditionalProperties.put("publishReference", publishReference);
Expand Down Expand Up @@ -160,8 +156,7 @@ public void thatUnsupportedArrayPropertiesAreIgnored() throws IOException {
assertThat(actual.getSystemAttributes(), equalTo(SYS_ATTRS));
assertThat(actual.getWorkflowStatus(), equalTo(WEB_READY));
assertThat(actual.getUsageTickets(), equalTo(TICKETS));
assertThat(actual.getWebUrl(), nullValue());


Map<String,String> expectedAdditionalProperties = new HashMap<>();
expectedAdditionalProperties.put("lastModified", lastModified);
expectedAdditionalProperties.put("publishReference", publishReference);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public class ArticlePreviewTransformationTest {
private static final String INVALID_EOM_FILE_TYPE = "NOT_COMPOUND_STORY";
private static final String PUBLISH_REF = "publishReference";
private static final String API_HOST = "test.api.ft.com";
private static final String WEB_URL_TEMPLATE = "https://www.ft.com/content/%s";
private static final String CANONICAL_WEB_URL_TEMPLATE = "https://www.ft.com/content/%s";
private FieldTransformer bodyTransformer = mock(FieldTransformer.class);
private FieldTransformer bylineTransformer = mock(FieldTransformer.class);
private BodyProcessor htmlFieldProcessor = spy(new Html5SelfClosingTagBodyProcessor());
Expand All @@ -54,12 +56,15 @@ public class ArticlePreviewTransformationTest {
private PostContentToTransformResource postContentToTransformResource;

@Before
public void setUp() throws Exception {
public void setUp() {
Map<ContentSource, Brand> contentSourceBrandMap = new HashMap<>();
contentSourceBrandMap.put(ContentSource.FT, new Brand(ARBITRARY_BRAND));

eomFileProcessor = new EomFileProcessor(EnumSet.allOf(TransformationMode.class), bodyTransformer, bylineTransformer, htmlFieldProcessor, contentSourceBrandMap, PUBLISH_REF, API_HOST);
postContentToTransformResource = new PostContentToTransformResource(eomFileProcessor, PropertySource.fromTransaction, PropertySource.fromTransaction, PUBLISH_REF);
eomFileProcessor = new EomFileProcessor(EnumSet.allOf(TransformationMode.class), bodyTransformer,
bylineTransformer, htmlFieldProcessor, contentSourceBrandMap, PUBLISH_REF, API_HOST,
WEB_URL_TEMPLATE, CANONICAL_WEB_URL_TEMPLATE);
postContentToTransformResource = new PostContentToTransformResource(eomFileProcessor,
PropertySource.fromTransaction, PropertySource.fromTransaction, PUBLISH_REF);

MDC.put("transaction_id", "transaction_id=" + TRANSACTION_ID);
}
Expand Down Expand Up @@ -102,6 +107,6 @@ static EomFile articlePreviewMinimalEomFile(String uuid) {
VALUE_PROPERTY.getBytes(),
ATTRIBUTES_PROPERTY,
WORKFLOW_STATUS[0],
SYSTEM_ATTRIBUTES_PROPERTY, null, null);
SYSTEM_ATTRIBUTES_PROPERTY, null);
}
}

0 comments on commit cb7b62f

Please sign in to comment.