Skip to content

Commit

Permalink
DXA 1.7 Sprint 4
Browse files Browse the repository at this point in the history
  • Loading branch information
rpannekoek committed Dec 13, 2016
2 parents 0b35e1f + 4673b13 commit 00094cf
Show file tree
Hide file tree
Showing 51 changed files with 1,457 additions and 314 deletions.
4 changes: 2 additions & 2 deletions dxa-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
</developers>

<properties>
<dd4t.version>2.1.2-DXA</dd4t.version>
<cd-cil.version>8.5.0-1005</cd-cil.version>
<dd4t.version>2.1.3-DXA17</dd4t.version>
<cd-cil.version>8.5.0-1007</cd-cil.version>

<!-- DXA versions -->
<dxa.version>${project.version}</dxa.version>
Expand Down
3 changes: 2 additions & 1 deletion dxa-builder/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ artifacts {
task signPom(type: Sign) {
sign configurations.pom
}
signPom.enabled = isRelease

task signJars(type: Sign, dependsOn: [jar, signPom, javadocJar, sourceJar]) {
sign configurations.archives
}
signJars.enabled = isRelease
task preparePublication(dependsOn: [signPom, signJars])
preparePublication.enabled = isRelease

task publishLocal(dependsOn: [build, publishToMavenLocal])
task publishRemote(dependsOn: [build, preparePublication, publish])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class Parameter {
Validator validator
String value

String versionAdded

private boolean valid = false

//region Builder methods
Expand Down Expand Up @@ -40,8 +42,23 @@ class Parameter {
this.value = project && project.hasProperty(cliName) ? (project[cliName] as String).trim() : defaultValue
this
}

Parameter versionAdded(String version) {
this.versionAdded = version
this
}
//endregion

boolean isSupportedInCurrentVersion(String currentVersion) {
if (!currentVersion || !versionAdded) {
return true
}
def normalize = { String version ->
Integer.parseInt(version.replaceAll(/[^\d]/, "").padRight(5, "0").substring(0, 5))
}
normalize(currentVersion) >= normalize(versionAdded)
}

String process(boolean batch, Map<String, ?> configuration = [:]) {
if (!this.value && this.dynamicDefault) {
this.value = this.dynamicDefault(configuration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,21 @@ class Validator {
})
}

static Validator domainName() {
new Validator(description: 'Should match a valid Domain Name', validate: { String it ->
static Validator domainName(boolean validWithPort = false) {
new Validator(description: "Should match a valid Domain Name ${validWithPort ? "with" : "without"} port", validate: { String it ->
def result = notEmpty().validate(it as String)

result &= !it.contains('://')
it = removePath(it)
notEmpty().validate(it as String) && DomainValidator.getInstance(true).isValid(it as String)

if (validWithPort) {
if (it.contains(':')) {
def arr = it.split(':')
it = arr[0]
result &= arr.length == 2 && intNumber().validate(arr[1])
}
}
result && DomainValidator.getInstance(true).isValid(it as String)
})
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.sdl.dxa.builder.configuration.parameters

import org.junit.Assert
import org.junit.Test

class ValidatorTest {

@Test
void shouldValidateDomainNames() {
//given
def validator = Validator.domainName()

//when, then
Assert.assertTrue(validator.validate("sdl.com"))
Assert.assertTrue(validator.validate("sdl.com/path"))
Assert.assertTrue(validator.validate("toplevel.sdl.com"))
Assert.assertTrue(validator.validate("toplevel.sdl.com/path/test"))


Assert.assertFalse(validator.validate("http://sdl.com"))
Assert.assertFalse(validator.validate("http://sdl.com/path"))
Assert.assertFalse(validator.validate("sdl.com:8080"))
Assert.assertFalse(validator.validate("sdl.com:8080/[ath"))
}

@Test
void shouldValidateDomainNamesWithPort() {
//given
def validator = Validator.domainName(true)

//when, then
Assert.assertTrue(validator.validate("sdl.com"))
Assert.assertTrue(validator.validate("sdl.com/path"))
Assert.assertTrue(validator.validate("toplevel.sdl.com"))
Assert.assertTrue(validator.validate("toplevel.sdl.com/path/text"))
Assert.assertTrue(validator.validate("sdl.com:8080"))
Assert.assertTrue(validator.validate("sdl.com:8080/path"))


Assert.assertFalse(validator.validate("http://sdl.com"))
Assert.assertFalse(validator.validate("http://sdl.com/path"))
Assert.assertFalse(validator.validate("http://sdl.com:8080"))
Assert.assertFalse(validator.validate("http://sdl.com:8080/path"))
Assert.assertFalse(validator.validate("sdl.com:8080:80"))
}

@Test
void shouldValidateIPs() {
//given
def validator = Validator.ip()

//when, then
Assert.assertTrue(validator.validate("127.0.0.1"))

//then
Assert.assertFalse(validator.validate("http://sdl.com"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ public final class EntitySemantics {

private final String entityName;

/**
* <p>Constructor for EntitySemantics.</p>
*
* @param vocabulary a {@link com.sdl.webapp.common.api.mapping.semantic.config.SemanticVocabulary} object.
* @param entityName a {@link java.lang.String} object.
*/
public EntitySemantics(SemanticVocabulary vocabulary, String entityName) {
this.vocabulary = vocabulary;
this.entityName = entityName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@
public final class FieldPath {

private final String head;

private final FieldPath tail;

/**
* <p>Constructor for FieldPath.</p>
*
* @param path a {@link java.lang.String} object.
*/
public FieldPath(String path) {
if (path.startsWith("/")) {
path = path.substring(1);
Expand All @@ -35,4 +31,8 @@ public FieldPath(String path) {
public boolean hasTail() {
return tail != null;
}

public boolean isMetadata() {
return "Metadata".equals(head);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ public final class FieldSemantics {

private final String propertyName;

/**
* <p>Constructor for FieldSemantics.</p>
*
* @param vocabulary a {@link com.sdl.webapp.common.api.mapping.semantic.config.SemanticVocabulary} object.
* @param entityName a {@link java.lang.String} object.
* @param propertyName a {@link java.lang.String} object.
*/
public FieldSemantics(SemanticVocabulary vocabulary, String entityName, String propertyName) {
this.vocabulary = vocabulary;
this.entityName = entityName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Map;

import static com.google.common.base.Strings.isNullOrEmpty;

@Getter
@ToString
@EqualsAndHashCode
@Slf4j
public final class SemanticField {

private final String name;
Expand All @@ -20,19 +26,45 @@ public final class SemanticField {

private final Map<FieldSemantics, SemanticField> embeddedFields;

/**
* <p>Constructor for SemanticField.</p>
*
* @param name a {@link java.lang.String} object.
* @param path a {@link java.lang.String} object.
* @param multiValue a boolean.
* @param embeddedFields a {@link java.util.Map} object.
*/
public SemanticField(String name, String path, boolean multiValue,
Map<FieldSemantics, SemanticField> embeddedFields) {
this.name = name;
this.path = new FieldPath(path);
this.multiValue = multiValue;
this.embeddedFields = ImmutableMap.copyOf(embeddedFields);
}

/**
* Generates XPath for this semantic field respecting the context XPath and type of the field (metadata or content).
*
* @param contextXPath the current context XPath, optional, may be {@code null}
* @return generated XPath
*/
@NotNull
public String getXPath(@Nullable String contextXPath) {
FieldPath pathCopy = path;

StringBuilder builder = new StringBuilder(pathCopy.isMetadata() ? "tcm:Metadata" : "tcm:Content");

while (true) {
builder.append("/custom:").append(pathCopy.getHead());
if (!pathCopy.hasTail()) {
break;
}
pathCopy = pathCopy.getTail();
}

String xPath = builder.toString();
String contextPathWithoutPredicate = null;
if (!isNullOrEmpty(contextXPath)) {
contextPathWithoutPredicate = contextXPath.split("\\[")[0];

if (!xPath.startsWith(contextPathWithoutPredicate)) {
// This should not happen, but if it happens, we just stick with the original XPath.
log.warn("Semantic field's XPath ('{}}') does not match context XPath '{}'.", xPath, contextXPath);
}
}

return contextPathWithoutPredicate == null ? xPath : xPath.replaceFirst(contextPathWithoutPredicate, contextXPath);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ public final class SemanticSchema {
@Setter
private Localization localization;

/**
* <p>Constructor for SemanticSchema.</p>
*
* @param id a long.
* @param rootElement a {@link java.lang.String} object.
* @param entitySemantics a {@link java.util.Set} object.
* @param semanticFields a {@link java.util.Map} object.
*/
public SemanticSchema(long id, String rootElement, Set<EntitySemantics> entitySemantics,
Map<FieldSemantics, SemanticField> semanticFields) {
this.id = id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,12 @@
@EqualsAndHashCode
public final class SemanticVocabulary {

/**
* Constant <code>SDL_CORE="http://www.sdl.com/web/schemas/core"</code>
*/
public static final String SDL_CORE = "http://www.sdl.com/web/schemas/core";
/**
* Constant <code>SCHEMA_ORG="http://schema.org/"</code>
*/

public static final String SCHEMA_ORG = "http://schema.org/";

/** Constant <code>SDL_CORE_VOCABULARY</code> */
public static final SemanticVocabulary SDL_CORE_VOCABULARY = new SemanticVocabulary(SDL_CORE);
/** Constant <code>SCHEMA_ORG_VOCABULARY</code> */

public static final SemanticVocabulary SCHEMA_ORG_VOCABULARY = new SemanticVocabulary(SCHEMA_ORG);

@Getter
Expand All @@ -34,11 +28,6 @@ public final class SemanticVocabulary {
@Setter
private String vocab;

/**
* <p>Constructor for SemanticVocabulary.</p>
*
* @param id a {@link java.lang.String} object.
*/
public SemanticVocabulary(String id) {
this.id = id;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.sdl.webapp.common.util;

import com.google.common.base.Function;
import com.google.common.collect.Lists;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static java.lang.Integer.parseInt;
import static org.apache.commons.lang3.StringUtils.isEmpty;

/**
* <p>StringUtils class.</p>
*/
public final class StringUtils {

/**
Expand All @@ -23,13 +24,36 @@ public static String convertFormatStringFromCM(String cmFormatString) {
}

StringBuffer out = new StringBuffer();
Pattern pattern = Pattern.compile("\\{(\\d)\\}");
Pattern pattern = Pattern.compile("\\{(\\d)}");
Matcher matcher = pattern.matcher(cmFormatString);
while (matcher.find()) {
String replacement = String.format("%%%d\\$s", parseInt(matcher.group().replaceAll("[\\{\\}]", "")) + 1);
String replacement = String.format("%%%d\\$s", parseInt(matcher.group().replaceAll("[{}]", "")) + 1);
matcher.appendReplacement(out, replacement);
}
matcher.appendTail(out);
return out.toString();
}


/**
* Transforms the list of any objects to the {@linkplain List list} of {@linkplain String strings}.
* Please note that {@code null} value is interpreted as {@code empty} value.
*
* @param list list to transform
* @return list of strings
*/
public static List<String> toStrings(List<?> list) {
return Lists.transform(list, new Function<Object, String>() {
@Override
public String apply(Object input) {
if (input == null) {
return "";
}
if (input instanceof String) {
return (String) input;
}
return input.toString();
}
});
}
}
Loading

0 comments on commit 00094cf

Please sign in to comment.