Skip to content

Commit

Permalink
UPPSF-5296 Add removal for CCC
Browse files Browse the repository at this point in the history
Similar to ImageSet, ClipSet and MediaResource add removal of CustomCodeComponent in the transformation chain.
  • Loading branch information
tsvetko24 committed May 23, 2024
1 parent da6a942 commit d63f105
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
9 changes: 8 additions & 1 deletion api-policy-component-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<maven-compiler-plugin.version>3.1</maven-compiler-plugin.version>
<maven-pmd-plugin.version>3.21.2</maven-pmd-plugin.version>
<checkstyle.version>2.10</checkstyle.version>
<findbugs.version>2.5.2</findbugs.version>
<findbugs.version>2.5.5</findbugs.version>
<dw.version>1.1.3</dw.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>4.11</junit.version>
Expand Down Expand Up @@ -231,6 +231,7 @@
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>${maven-pmd-plugin.version}</version>
<executions>
Expand All @@ -243,6 +244,7 @@
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>${maven-jxr-plugin.version}</version>
<executions>
Expand All @@ -255,6 +257,7 @@
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1${maven-shade-plugin.version}6</version>
<executions>
Expand Down Expand Up @@ -288,6 +291,7 @@
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven-resources-plugin.version}</version>
<executions>
Expand Down Expand Up @@ -323,6 +327,7 @@
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
Expand All @@ -332,6 +337,7 @@
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven-source-plugin.version}</version>
<executions>
Expand All @@ -344,6 +350,7 @@
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version>
<configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ public class BodyTransformationXMLEventRegistry extends XMLEventHandlerRegistry

private static final String IMAGE_SET_CLASS_URI = "http://www.ft.com/ontology/content/ImageSet";
private static final String CLIP_SET_CLASS_URI = "http://www.ft.com/ontology/content/ClipSet";
private static final String TYPE = "type";
private static final String CUSTOM_CODE_COMPONENT_CLASS_URI =
"http://www.ft.com/ontology/content/CustomCodeComponent";
private static final String MEDIA_RESOURCE_CLASS_URI =
"http://www.ft.com/ontology/content/MediaResource";
private static final String TYPE = "type";
private static final String FT_CONTENT = "ft-content";
private static final String[] elementsToStrip = {
"pull-quote", "promo-box", "ft-related", "timeline", "ft-timeline", "table", "big-number", "img"
Expand Down Expand Up @@ -56,7 +58,10 @@ private static XMLEventHandler getChainedXmlEventHandlers() {
final XMLEventHandler removeImageSet =
new StripElementIfSpecificAttributesXmlEventHandler(
Collections.singletonMap(TYPE, IMAGE_SET_CLASS_URI), removeMediaResource);
final XMLEventHandler removeCustomCodeComponent =
new StripElementIfSpecificAttributesXmlEventHandler(
Collections.singletonMap(TYPE, CUSTOM_CODE_COMPONENT_CLASS_URI), removeImageSet);
return new StripElementIfSpecificAttributesXmlEventHandler(
Collections.singletonMap(TYPE, CLIP_SET_CLASS_URI), removeImageSet);
Collections.singletonMap(TYPE, CLIP_SET_CLASS_URI), removeCustomCodeComponent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ public void testShouldRemoveInlineExternalImages() {
checkTransformation(original, expected);
}

@Test
public void shouldRemoveCustomCodeComponentAndStripOutSurroundingTag() {
String original =
"<body><p>He sheltered there - CustomCodeComponent.</p>\n<p><ft-content data-embedded=\"true\" type=\"http://www.ft.com/ontology/content/CustomCodeComponent\" url=\"http://api.ft.com/content/11111111-1111-1111-1111-11111111111\"></ft-content></p>\n<p>“I saw bodies everywhere.”</p>\n\n\n\n</body>";
String expected =
"<body><p>He sheltered there - CustomCodeComponent.</p>\n<p>“I saw bodies everywhere.”</p>\n\n\n\n</body>";

checkTransformation(original, expected);
}

private void checkTransformation(String originalBody, String expectedTransformedBody) {
String actualTransformedBody = bodyTransformer.transform(originalBody, TRANSACTION_ID);
assertThat(actualTransformedBody, is(equivalentToUnixString(expectedTransformedBody)));
Expand Down

0 comments on commit d63f105

Please sign in to comment.