use of com.enonic.xp.content.ValidationErrors in project xp by enonic.
the class RenameContentCommand method doExecute.
private Content doExecute() {
final NodeId nodeId = NodeId.from(params.getContentId());
final NodeName nodeName = NodeName.from(params.getNewName().toString());
final RenameNodeParams.Builder builder = RenameNodeParams.create().nodeId(nodeId).nodeName(nodeName);
if (params.stopInherit()) {
builder.processor(new RenameContentProcessor());
}
final Node node = nodeService.rename(builder.build());
final Content content = translator.fromNode(node, false);
final ValidationErrors validationErrors = validateContent(content);
if (content.isValid() == validationErrors.hasErrors() || !validationErrors.equals(content.getValidationErrors())) {
return updateValidState(content);
}
return getContent(params.getContentId());
}
use of com.enonic.xp.content.ValidationErrors in project xp by enonic.
the class ValidateContentDataCommandTest method testSiteConfigTextRegexpPasses.
@Test
public void testSiteConfigTextRegexpPasses() {
final ContentType contentType = ContentType.create().superType(ContentTypeName.structured()).name(ContentTypeName.site()).build();
Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenReturn(contentType);
PropertyTree rootDataSet = new PropertyTree();
PropertyTree siteConfigDataSet = new PropertyTree();
siteConfigDataSet.setString("textInput-1", "1234");
SiteConfig siteConfig = SiteConfig.create().application(ApplicationKey.from("myapp")).config(siteConfigDataSet).build();
new SiteConfigsDataSerializer().toProperties(SiteConfigs.from(siteConfig), rootDataSet.getRoot());
Mockito.when(siteService.getDescriptor(Mockito.isA(ApplicationKey.class))).thenReturn(createSiteDescriptor());
// exercise
final ValidationErrors result = executeValidation(rootDataSet, ContentTypeName.site());
assertFalse(result.hasErrors());
}
use of com.enonic.xp.content.ValidationErrors in project xp by enonic.
the class ValidateContentDataCommandTest method validation_with_errors.
@Test
public void validation_with_errors() {
// setup
final ContentType contentType = ContentType.create().superType(ContentTypeName.structured()).name("myapplication:my_type").addFormItem(FieldSet.create().label("My layout").name("myLayout").addFormItem(FormItemSet.create().name("mySet").required(true).addFormItem(Input.create().name("myInput").label("Input").inputType(InputTypeName.TEXT_LINE).build()).build()).build()).build();
Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenReturn(contentType);
final Content content = Content.create().path("/mycontent").type(contentType.getName()).build();
final ValidationErrors result = executeValidation(content.getData(), contentType.getName());
// test
assertTrue(result.hasErrors());
assertThat(result.stream()).hasSize(1);
}
use of com.enonic.xp.content.ValidationErrors in project xp by enonic.
the class ValidateContentDataCommandTest method test_unnamed.
@Test
public void test_unnamed() {
// setup
final FieldSet fieldSet = FieldSet.create().label("My layout").name("myLayout").addFormItem(FormItemSet.create().name("mySet").required(true).addFormItem(Input.create().name("myInput").label("Input").inputType(InputTypeName.TEXT_LINE).build()).build()).build();
final ContentType contentType = ContentType.create().superType(ContentTypeName.structured()).name("myapplication:my_type").addFormItem(fieldSet).build();
Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenReturn(contentType);
final Content content = Content.create().path("/mycontent").type(contentType.getName()).name(ContentName.unnamed()).displayName("display-name").build();
content.getData().setString("mySet.myInput", "thing");
// exercise
final ValidationErrors result = executeValidation(content.getData(), contentType.getName(), content.getName(), content.getDisplayName());
assertThat(result.stream()).hasSize(1);
}
use of com.enonic.xp.content.ValidationErrors in project xp by enonic.
the class ValidateContentDataCommandTest method validation_no_errors.
@Test
public void validation_no_errors() {
// setup
final FieldSet fieldSet = FieldSet.create().label("My layout").name("myLayout").addFormItem(FormItemSet.create().name("mySet").required(true).addFormItem(Input.create().name("myInput").label("Input").inputType(InputTypeName.TEXT_LINE).build()).build()).build();
final ContentType contentType = ContentType.create().superType(ContentTypeName.structured()).name("myapplication:my_type").addFormItem(fieldSet).build();
Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenReturn(contentType);
final Content content = Content.create().path("/mycontent").type(contentType.getName()).build();
content.getData().setString("mySet.myInput", "thing");
// exercise
final ValidationErrors result = executeValidation(content.getData(), contentType.getName());
assertFalse(result.hasErrors());
}
Aggregations