Search in sources :

Example 1 with ContentTypeValidationError

use of com.enonic.xp.schema.content.validator.ContentTypeValidationError in project xp by enonic.

the class ContentTypeSuperTypeValidator method validate.

public void validate(final ContentTypeName contentTypeName, final ContentTypeName superTypeContentName) {
    if (superTypeContentName != null) {
        final GetContentTypeParams params = new GetContentTypeParams().contentTypeName(superTypeContentName);
        final ContentType superType = contentTypeService.getByName(params);
        if (superType == null) {
            registerError(new ContentTypeValidationError("superType not found: " + superTypeContentName, contentTypeName));
            return;
        }
        if (superType.isFinal()) {
            registerError(new ContentTypeValidationError("Cannot inherit from a final ContentType: " + superType.getName(), contentTypeName));
        }
    }
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) ContentType(com.enonic.xp.schema.content.ContentType) ContentTypeValidationError(com.enonic.xp.schema.content.validator.ContentTypeValidationError)

Example 2 with ContentTypeValidationError

use of com.enonic.xp.schema.content.validator.ContentTypeValidationError in project xp by enonic.

the class SuperTypeValidatorTest method validationResult.

@Test
public void validationResult() {
    ContentTypeValidationResult validationResult1 = ContentTypeValidationResult.from(new ContentTypeValidationError("superType not found: superTypeName", ContentTypeName.media()));
    ContentTypeValidationResult validationResult2 = ContentTypeValidationResult.from(Collections.singleton(new ContentTypeValidationError("superType not found: superTypeName", ContentTypeName.media())));
    ContentTypeValidationResult validationResult3 = ContentTypeValidationResult.empty();
    assertNotEquals(validationResult1, validationResult2);
    assertNotEquals(validationResult1.hashCode(), validationResult2.hashCode());
    assertFalse(validationResult3.hasErrors());
    assertNotEquals(validationResult2.hashCode(), validationResult3.hashCode());
    assertNotEquals(validationResult2.toString(), validationResult3.toString());
}
Also used : ContentTypeValidationResult(com.enonic.xp.schema.content.validator.ContentTypeValidationResult) ContentTypeValidationError(com.enonic.xp.schema.content.validator.ContentTypeValidationError) Test(org.junit.jupiter.api.Test)

Aggregations

ContentTypeValidationError (com.enonic.xp.schema.content.validator.ContentTypeValidationError)2 ContentType (com.enonic.xp.schema.content.ContentType)1 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)1 ContentTypeValidationResult (com.enonic.xp.schema.content.validator.ContentTypeValidationResult)1 Test (org.junit.jupiter.api.Test)1