-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#26 adding validators for the ConsentFormCheckBox and GroupElement fi…
…elds. And Studio-Labels for all validators
- Loading branch information
1 parent
e28bcb7
commit 8ab9780
Showing
11 changed files
with
300 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...ib/src/main/java/com/tallence/formeditor/studio/validator/field/ConsentFormValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright 2018 Tallence AG | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.tallence.formeditor.studio.validator.field; | ||
|
||
import com.coremedia.blueprint.base.util.StructUtil; | ||
import com.coremedia.cap.struct.Struct; | ||
import com.coremedia.rest.validation.Issues; | ||
import com.coremedia.rest.validation.Severity; | ||
import com.tallence.formeditor.contentbeans.FormEditor; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.util.StringUtils; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* Validates, that ConsentFormCheckBoxes have a text and a link. | ||
*/ | ||
@Component | ||
public class ConsentFormValidator implements FieldValidator { | ||
@Override | ||
public List<String> resonsibleFor() { | ||
return Collections.singletonList("ConsentFormCheckBox"); | ||
} | ||
|
||
@Override | ||
public void validateField(Struct fieldData, String action, Issues issues) { | ||
|
||
String name = StructUtil.getString(fieldData, "name"); | ||
if (fieldData.get("linkTarget") == null) { | ||
issues.addIssue(Severity.ERROR, FormEditor.FORM_ELEMENTS, "consentForm_missing_linkTarget", name); | ||
} | ||
|
||
String hint = StructUtil.getString(fieldData, "hint"); | ||
if (StringUtils.isEmpty(hint)) { | ||
issues.addIssue(Severity.ERROR, FormEditor.FORM_ELEMENTS, "consentForm_missing_hint", name); | ||
} else if (!hint.matches(".*%.+%.*")) { | ||
issues.addIssue(Severity.ERROR, FormEditor.FORM_ELEMENTS, "consentForm_invalid_hint", name); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...rc/main/java/com/tallence/formeditor/studio/validator/field/OptionsNotEmptyValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright 2018 Tallence AG | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.tallence.formeditor.studio.validator.field; | ||
|
||
import com.coremedia.blueprint.base.util.StructUtil; | ||
import com.coremedia.cap.struct.Struct; | ||
import com.coremedia.rest.validation.Issues; | ||
import com.coremedia.rest.validation.Severity; | ||
import com.tallence.formeditor.contentbeans.FormEditor; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Validates, that CheckBoxes, DropDowns and RadioButtons have at least one groupElement. | ||
*/ | ||
@Component | ||
public class OptionsNotEmptyValidator implements FieldValidator { | ||
@Override | ||
public List<String> resonsibleFor() { | ||
return Arrays.asList("RadioButtons", "CheckBoxes", "SelectBox"); | ||
} | ||
|
||
@Override | ||
public void validateField(Struct fieldData, String action, Issues issues) { | ||
|
||
boolean noElements = Optional.ofNullable(StructUtil.getSubstruct(fieldData, "groupElements")) | ||
.map(s -> s.getProperties().isEmpty()) | ||
.orElse(true); | ||
if (noElements) { | ||
|
||
String messageKey = fieldData.getString("type").toLowerCase() + "_missing_options"; | ||
|
||
issues.addIssue(Severity.ERROR, FormEditor.FORM_ELEMENTS, messageKey, fieldData.getString("name")); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...studio-lib/src/test/resources/com/tallence/formeditor/studio/validator/10formElements.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<!-- | ||
~ Copyright 2018 Tallence AG | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<Struct xmlns="http://www.coremedia.com/2008/struct"> | ||
<StructProperty Name="formElements"> | ||
<Struct> | ||
<StructProperty Name="Test Buttons without options"> | ||
<Struct> | ||
<StringProperty Name="type">RadioButtons</StringProperty> | ||
<StringProperty Name="name">without buttons</StringProperty> | ||
</Struct> | ||
</StructProperty> | ||
<StructProperty Name="Test Buttons with options"> | ||
<Struct> | ||
<StringProperty Name="type">RadioButtons</StringProperty> | ||
<StringProperty Name="name">with button</StringProperty> | ||
<StructProperty Name="groupElements"> | ||
<Struct> | ||
<StructProperty Name="Button 1"/> | ||
</Struct> | ||
</StructProperty> | ||
</Struct> | ||
</StructProperty> | ||
</Struct> | ||
</StructProperty> | ||
</Struct> |
52 changes: 52 additions & 0 deletions
52
...studio-lib/src/test/resources/com/tallence/formeditor/studio/validator/12formElements.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<!-- | ||
~ Copyright 2018 Tallence AG | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<Struct xmlns="http://www.coremedia.com/2008/struct" xmlns:xlink="http://www.w3.org/1999/xlink"> | ||
<StructProperty Name="formElements"> | ||
<Struct> | ||
<StructProperty Name="ConsentForm valid"> | ||
<Struct> | ||
<StringProperty Name="type">ConsentFormCheckBox</StringProperty> | ||
<StringProperty Name="name">ConsentForm valid</StringProperty> | ||
<StringProperty Name="hint">That is the %target%</StringProperty> | ||
<LinkProperty Name="linkTarget" LinkType="CMLinkable" xlink:href="coremedia:///cap/content/2"/> | ||
</Struct> | ||
</StructProperty> | ||
<StructProperty Name="ConsentForm missing target"> | ||
<Struct> | ||
<StringProperty Name="type">ConsentFormCheckBox</StringProperty> | ||
<StringProperty Name="name">ConsentForm missing target</StringProperty> | ||
<StringProperty Name="hint">That is the %target%</StringProperty> | ||
</Struct> | ||
</StructProperty> | ||
<StructProperty Name="ConsentForm missing hint"> | ||
<Struct> | ||
<StringProperty Name="type">ConsentFormCheckBox</StringProperty> | ||
<StringProperty Name="name">ConsentForm missing hint</StringProperty> | ||
<LinkProperty Name="linkTarget" LinkType="CMLinkable" xlink:href="coremedia:///cap/content/2"/> | ||
</Struct> | ||
</StructProperty> | ||
<StructProperty Name="ConsentForm invalid hint"> | ||
<Struct> | ||
<StringProperty Name="type">ConsentFormCheckBox</StringProperty> | ||
<StringProperty Name="name">ConsentForm invalid hint</StringProperty> | ||
<LinkProperty Name="linkTarget" LinkType="CMLinkable" xlink:href="coremedia:///cap/content/2"/> | ||
<StringProperty Name="hint">Hint without placeholder</StringProperty> | ||
</Struct> | ||
</StructProperty> | ||
</Struct> | ||
</StructProperty> | ||
</Struct> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.