Commit c10ce20f authored by Szabolcs Gyurko's avatar Szabolcs Gyurko
Browse files

Added component name property

parent 39c70c1e
Pipeline #291 passed with stage
in 2 minutes and 57 seconds
......@@ -63,8 +63,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.11</source>
<target>1.11</target>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
......
......@@ -2,7 +2,7 @@ import React, {Component} from 'react';
import logo from '../logo.svg';
import '../App.css';
export default class Auth extends Component {
export default class Home extends Component {
render() {
return (
<div className="Main">
......
......@@ -198,8 +198,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.11</source>
<target>1.11</target>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
......
......@@ -182,8 +182,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.11</source>
<target>1.11</target>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
......
......@@ -131,8 +131,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.11</source>
<target>1.11</target>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
......
......@@ -29,6 +29,7 @@ import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
......@@ -64,6 +65,11 @@ public class ComponentToNodePropertiesConverter implements Converter<com.jeff_cm
properties.add(headScripts);
properties.add(styles);
final NodeProperty name = new NodeProperty();
name.setName(componentPrefix);
name.setValues(Collections.singletonList(component.getName()));
properties.add(name);
return properties;
}
}
......@@ -43,7 +43,7 @@ public class NodePropertiesToComponentConverter implements Converter<List<NodePr
final com.jeff_cms.jeff.web.model.Component component = new com.jeff_cms.jeff.web.model.Component();
if (properties.size() > 0) {
final String id = properties.get(0).getName().replaceAll("jc_([0-9a-z\\-]+)_.*", "$1");
final String id = properties.get(0).getName().replaceAll("jc_([0-9a-z\\-]+)_.+", "$1");
final String componentPrefix = "jc_" + id + "_";
component.setId(id);
component.setHeadScripts(new HashSet<>(
......@@ -82,15 +82,17 @@ public class NodePropertiesToComponentConverter implements Converter<List<NodePr
component.setData(properties.stream().filter(p ->
!p.getName().equals(componentPrefix + "styles")
&& !p.getName().equals(componentPrefix + "scripts")
&& !p.getName().equals(componentPrefix + "headScripts"))
&& !p.getName().equals(componentPrefix + "headScripts")
&& !p.getName().equals(componentPrefix))
.map(np -> {
final NodeProperty nodeProperty = new NodeProperty();
nodeProperty.setName(np.getName().replaceAll("jc_[0-9a-z\\-]+_(.*)", "$1"));
nodeProperty.setName(np.getName().replaceAll("jc_[0-9a-z\\-]+_(.+)", "$1"));
nodeProperty.setValues(np.getValues());
return nodeProperty;
})
.collect(Collectors.toMap(NodeProperty::getName, NodeProperty::getValues))
);
component.setName(properties.stream().filter(p -> p.getName().equals(componentPrefix)).findFirst().orElseGet(NodeProperty::new).getValue());
}
return component;
......
......@@ -77,11 +77,11 @@ public class NodeToPageConverter implements Converter<Node, Page> {
page.setMetaData(metaData);
/* Components */
page.setComponents(node.getProperties().stream().filter(p -> p.getName().matches("jc_[0-9a-z\\-]+_.*"))
.map(p -> p.getName().replaceAll("jc_([0-9a-z\\-]+)_.*", "$1"))
page.setComponents(node.getProperties().stream().filter(p -> p.getName().matches("jc_[0-9a-z\\-]+_.+"))
.map(p -> p.getName().replaceAll("jc_([0-9a-z\\-]+)_.+", "$1"))
.distinct()
.map(id -> conversionService.convert(node.getProperties().stream()
.filter(p -> p.getName().matches("jc_" + id + "_.*"))
.filter(p -> p.getName().matches("jc_" + id + "_.+"))
.collect(Collectors.toList()),
com.jeff_cms.jeff.web.model.Component.class)
).collect(Collectors.toList())
......
......@@ -36,6 +36,7 @@ import java.util.Set;
@Data
public class Component {
private String id;
private String name;
private Map<String, List<String>> data;
private Set<String> headScripts;
private Set<String> scripts;
......
......@@ -39,6 +39,7 @@ public class ComponentToNodePropertiesConverterTest {
final Component component = new Component();
component.setId(UUID.randomUUID().toString());
component.setName("testComponent");
component.setStyles(Collections.singleton("http://test.com/style.css"));
component.setScripts(new HashSet<>(Arrays.asList("http://test.com/script1.js", "http://test.com/script2.js")));
component.setHeadScripts(Collections.singleton("http://test.com/script3.js"));
......@@ -51,12 +52,13 @@ public class ComponentToNodePropertiesConverterTest {
final List<NodeProperty> nodeProperties = converter.convert(component);
Assert.assertNotNull(nodeProperties);
Assert.assertEquals(5, nodeProperties.size());
Assert.assertEquals(5, nodeProperties.stream().filter(p -> p.getName().matches("jc_" + component.getId() + "_.*")).count());
Assert.assertEquals(6, nodeProperties.size());
Assert.assertEquals(5, nodeProperties.stream().filter(p -> p.getName().matches("jc_" + component.getId() + "_.+")).count());
Assert.assertEquals("http://test.com/style.css", nodeProperties.stream().filter(p -> p.getName().equals("jc_" + component.getId() + "_styles")).findFirst().orElseThrow(() -> new RuntimeException("Styles not found")).getValue());
Assert.assertEquals("http://test.com/script3.js", nodeProperties.stream().filter(p -> p.getName().equals("jc_" + component.getId() + "_headScripts")).findFirst().orElseThrow(() -> new RuntimeException("Head Scripts not found")).getValue());
Assert.assertEquals(2, nodeProperties.stream().filter(p -> p.getName().equals("jc_" + component.getId() + "_scripts")).findFirst().orElseThrow(() -> new RuntimeException("Head Scripts not found")).getValues().size());
Assert.assertEquals("testProperty1", nodeProperties.stream().filter(p -> p.getName().equals("jc_" + component.getId() + "_test1")).findFirst().orElseThrow(() -> new RuntimeException("Head Scripts not found")).getValue());
Assert.assertEquals(2, nodeProperties.stream().filter(p -> p.getName().equals("jc_" + component.getId() + "_test2")).findFirst().orElseThrow(() -> new RuntimeException("Head Scripts not found")).getValues().size());
Assert.assertEquals("testComponent", nodeProperties.stream().filter(p -> p.getName().equals("jc_" + component.getId() + "_")).findFirst().orElseThrow(() -> new RuntimeException("Component name not found")).getValue());
}
}
\ No newline at end of file
......@@ -60,6 +60,10 @@ public class NodePropertiesToComponentConverterTest {
testProp5.setName(componentPrefix + "test2");
testProp5.setValues(Arrays.asList("testProperty2", "testProperty3"));
nodeProperties.add(testProp5);
final NodeProperty testProp6 = new NodeProperty();
testProp6.setName(componentPrefix);
testProp6.setValues(Collections.singletonList("componentName"));
nodeProperties.add(testProp6);
final Component component = converter.convert(nodeProperties);
......@@ -82,5 +86,6 @@ public class NodePropertiesToComponentConverterTest {
Assert.assertEquals("http://test.com/script1.js", component.getScripts().iterator().next());
Assert.assertEquals("http://test.com/script2.js", component.getHeadScripts().iterator().next());
Assert.assertEquals("http://test.com/style.css", component.getStyles().iterator().next());
Assert.assertEquals("componentName", component.getName());
}
}
\ No newline at end of file
......@@ -52,6 +52,7 @@ public class PageToNodeConverterTest {
final Component component1 = new Component();
component1.setId(UUID.randomUUID().toString());
component1.setName("testComponent1");
component1.setStyles(Collections.singleton("http://test.com/style.css"));
component1.setScripts(new HashSet<>(Arrays.asList("http://test.com/script1.js", "http://test.com/script2.js")));
component1.setHeadScripts(Collections.singleton("http://test.com/script3.js"));
......@@ -64,6 +65,7 @@ public class PageToNodeConverterTest {
final Component component2 = new Component();
component2.setId(UUID.randomUUID().toString());
component2.setName("testComponent2");
component2.setStyles(Collections.singleton("http://test2.com/style.css"));
component2.setScripts(new HashSet<>(Arrays.asList("http://test2.com/script1.js", "http://test2.com/script2.js")));
component2.setHeadScripts(Collections.singleton("http://test2.com/script3.js"));
......@@ -82,11 +84,11 @@ public class PageToNodeConverterTest {
final Node node = conversionService.convert(page, Node.class);
Assert.assertNotNull(node);
Assert.assertEquals(12, node.getProperties().size());
Assert.assertEquals(14, node.getProperties().size());
Assert.assertEquals(2, node.getProperties().stream()
.filter(np -> np.getName().matches("jc_.*"))
.filter(np -> np.getName().matches("jc_[0-9a-z\\-]+_.+"))
.map(NodeProperty::getName)
.map(n -> n.replaceAll("jc_([0-9a-z\\-]+)_.*", "$1"))
.map(n -> n.replaceAll("jc_([0-9a-z\\-]+)_.+", "$1"))
.distinct()
.count()
);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment