use of com.enonic.xp.schema.content.ContentTypeName in project xp by enonic.
the class ContentTypeFilterTypeTest method testContentFilterIteration.
@Test
public void testContentFilterIteration() throws Exception {
final ContentTypeFilter filter = ContentTypeFilter.create().defaultAllow().denyContentType(ContentTypeName.from("myapplication:com.enonic.tweet")).denyContentType("myapplication:system.folder").denyContentTypes(ContentTypeNames.from("myapplication:com.enonic.article", "myapplication:com.enonic.employee")).build();
final Iterator<ContentTypeName> iterator = filter.iterator();
assertEquals(ContentTypeName.from("myapplication:com.enonic.tweet"), iterator.next());
assertEquals(ContentTypeName.from("myapplication:system.folder"), iterator.next());
assertEquals(ContentTypeName.from("myapplication:com.enonic.article"), iterator.next());
assertEquals(ContentTypeName.from("myapplication:com.enonic.employee"), iterator.next());
assertFalse(iterator.hasNext());
}
use of com.enonic.xp.schema.content.ContentTypeName in project xp by enonic.
the class ContentQueryNodeQueryTranslator method processContentTypesNames.
private static void processContentTypesNames(final ContentQuery contentQuery, final NodeQuery.Builder builder) {
final ContentTypeNames contentTypeNames = contentQuery.getContentTypes();
if (contentTypeNames != null && contentTypeNames.isNotEmpty()) {
final ValueFilter.Builder contentTypeFilterBuilder = ValueFilter.create().fieldName(ContentPropertyNames.TYPE).setCache(true);
for (final ContentTypeName contentTypeName : contentTypeNames) {
contentTypeFilterBuilder.addValue(ValueFactory.newString(contentTypeName.toString()));
}
builder.addQueryFilter(contentTypeFilterBuilder.build());
}
}
use of com.enonic.xp.schema.content.ContentTypeName in project xp by enonic.
the class UpdateContentCommand method doExecute.
private Content doExecute() {
final Content contentBeforeChange = getContent(params.getContentId());
Content editedContent = editContent(params.getEditor(), contentBeforeChange);
if (params.stopInherit()) {
if (editedContent.getInherit().contains(ContentInheritType.CONTENT)) {
nodeService.commit(NodeCommitEntry.create().message("Base inherited version").build(), NodeIds.from(params.getContentId().toString()));
editedContent.getInherit().remove(ContentInheritType.CONTENT);
}
editedContent.getInherit().remove(ContentInheritType.NAME);
}
final BinaryReferences removeAttachments = Objects.requireNonNullElseGet(params.getRemoveAttachments(), BinaryReferences::empty);
if (contentBeforeChange.equals(editedContent) && params.getCreateAttachments() == null && removeAttachments.isEmpty() && !this.params.isClearAttachments()) {
return contentBeforeChange;
}
editedContent = processContent(contentBeforeChange, editedContent);
validateBlockingChecks(editedContent);
final ValidationErrors.Builder validationErrorsBuilder = ValidationErrors.create();
if (!params.isClearAttachments() && contentBeforeChange.getValidationErrors() != null) {
contentBeforeChange.getValidationErrors().stream().filter(validationError -> validationError instanceof AttachmentValidationError).map(validationError -> (AttachmentValidationError) validationError).filter(validationError -> !removeAttachments.contains(validationError.getAttachment())).forEach(validationErrorsBuilder::add);
}
final ValidationErrors validationErrors = ValidateContentDataCommand.create().contentId(editedContent.getId()).data(editedContent.getData()).extraDatas(editedContent.getAllExtraData()).contentTypeName(editedContent.getType()).contentName(editedContent.getName()).displayName(editedContent.getDisplayName()).createAttachments(params.getCreateAttachments()).contentValidators(this.contentValidators).contentTypeService(this.contentTypeService).validationErrorsBuilder(validationErrorsBuilder).build().execute();
if (params.isRequireValid()) {
validationErrors.stream().findFirst().ifPresent(validationError -> {
throw new ContentDataValidationException(validationError.getMessage());
});
}
editedContent = Content.create(editedContent).valid(!validationErrors.hasErrors()).validationErrors(validationErrors).build();
editedContent = attachThumbnail(editedContent);
editedContent = setModifiedTime(editedContent);
final UpdateContentTranslatorParams updateContentTranslatorParams = UpdateContentTranslatorParams.create().editedContent(editedContent).createAttachments(this.params.getCreateAttachments()).removeAttachments(this.params.getRemoveAttachments()).clearAttachments(this.params.isClearAttachments()).modifier(getCurrentUser().getKey()).build();
final UpdateNodeParams updateNodeParams = UpdateNodeParamsFactory.create(updateContentTranslatorParams).contentTypeService(this.contentTypeService).xDataService(this.xDataService).pageDescriptorService(this.pageDescriptorService).partDescriptorService(this.partDescriptorService).layoutDescriptorService(this.layoutDescriptorService).contentDataSerializer(this.contentDataSerializer).siteService(this.siteService).build().produce();
final Node editedNode = this.nodeService.update(updateNodeParams);
return translator.fromNode(editedNode, true);
}
use of com.enonic.xp.schema.content.ContentTypeName in project xp by enonic.
the class ApplicationRelativeResolverTest method toContentTypeName.
@Test
public void toContentTypeName() {
final ApplicationRelativeResolver resolver = new ApplicationRelativeResolver(ApplicationKey.from("aaa"));
ContentTypeName contentTypeName = resolver.toContentTypeName("bbb");
assertEquals(contentTypeName.getLocalName(), "bbb");
contentTypeName = resolver.toContentTypeName("ccc:ddd");
assertEquals(contentTypeName.getLocalName(), "ddd");
}
use of com.enonic.xp.schema.content.ContentTypeName in project xp by enonic.
the class AbstractContentCommand method validateParentChildRelations.
protected void validateParentChildRelations(final ContentPath parentPath, final ContentTypeName typeName) {
if (parentPath.isRoot()) {
// root allows anything except page-template and template-folder.
if (typeName.isPageTemplate() || typeName.isTemplateFolder()) {
throw new IllegalArgumentException(String.format("A content with type '%s' cannot be a child of root", typeName));
} else {
return;
}
}
final Content parent = GetContentByPathCommand.create(parentPath, this).build().execute();
if (parent == null) {
throw new IllegalStateException(String.format("Cannot read parent type with path %s", parentPath));
}
final ContentTypeName parentTypeName = parent.getType();
if ((typeName.isTemplateFolder() && !parentTypeName.isSite()) || (typeName.isPageTemplate() && !parentTypeName.isTemplateFolder())) {
throw new IllegalArgumentException(String.format("A content with type '%s' cannot be a child of '%s' with path %s", typeName, parentTypeName, parentPath));
}
final ContentType parentType = contentTypeService.getByName(GetContentTypeParams.from(parentTypeName));
if (parentType == null) {
LOG.debug("Bypass validation for unknown content type of parent with path {}", parentPath);
return;
}
if (!parentType.allowChildContent()) {
throw new IllegalArgumentException(String.format("Child content is not allowed in '%s' with path %s", parentTypeName, parentPath));
}
final boolean isAllowed = allowContentTypeFilter(parentTypeName.getApplicationKey(), parentType.getAllowChildContentType()).test(typeName);
if (!isAllowed) {
throw new IllegalArgumentException(String.format("A content with type '%s' cannot be a child of '%s' with path %s", typeName, parentTypeName, parentPath));
}
}
Aggregations