use of com.enonic.xp.schema.content.ContentType in project xp by enonic.
the class CreateContentCommandTest method nameGeneratedFromDisplayName.
@Test
public void nameGeneratedFromDisplayName() {
final CreateContentParams params = createContentParams().build();
final CreateContentCommand command = createContentCommand(params);
final ContentType contentType = ContentType.create().superType(ContentTypeName.documentMedia()).name(ContentTypeName.dataMedia()).build();
Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenReturn(contentType);
mockContentRootNode();
// exercise
final Content createdContent = command.execute();
assertEquals(ContentName.from("displayname"), createdContent.getName());
}
use of com.enonic.xp.schema.content.ContentType in project xp by enonic.
the class HtmlAreaContentProcessor method processUpdate.
@Override
public ProcessUpdateResult processUpdate(final ProcessUpdateParams params) {
final CreateAttachments createAttachments = params.getCreateAttachments();
final ContentEditor editor;
editor = editable -> {
final ContentIds.Builder processedIds = ContentIds.create();
final ContentType contentType = contentTypeService.getByName(GetContentTypeParams.from(editable.source.getType()));
processContentData(editable.data, contentType, processedIds);
processExtraData(editable.extraDatas, processedIds);
processPageData(editable.page, processedIds);
if (editable instanceof EditableSite) {
processSiteConfigData(((EditableSite) editable).siteConfigs, processedIds);
}
editable.processedReferences = processedIds;
};
return new ProcessUpdateResult(createAttachments, editor);
}
use of com.enonic.xp.schema.content.ContentType in project xp by enonic.
the class CreateContentCommand method doExecute.
private Content doExecute() {
final ContentType contentType = contentTypeService.getByName(new GetContentTypeParams().contentTypeName(params.getType()));
validateContentType(contentType);
formDefaultValuesProcessor.setDefaultValues(contentType.getForm(), params.getData());
// TODO apply default values to xData
CreateContentParams processedParams = runContentProcessors(this.params, contentType);
validateBlockingChecks(processedParams);
final CreateContentTranslatorParams createContentTranslatorParams = createContentTranslatorParams(processedParams);
final CreateNodeParams createNodeParams = CreateNodeParamsFactory.create(createContentTranslatorParams).contentTypeService(this.contentTypeService).pageDescriptorService(this.pageDescriptorService).xDataService(this.xDataService).partDescriptorService(this.partDescriptorService).layoutDescriptorService(this.layoutDescriptorService).contentDataSerializer(this.contentDataSerializer).siteService(this.siteService).build().produce();
try {
final Node createdNode = nodeService.create(createNodeParams);
if (params.isRefresh()) {
nodeService.refresh(RefreshMode.SEARCH);
}
return translator.fromNode(createdNode, false);
} catch (NodeAlreadyExistAtPathException e) {
throw new ContentAlreadyExistsException(ContentPath.from(createContentTranslatorParams.getParent(), createContentTranslatorParams.getName().toString()), e.getRepositoryId(), e.getBranch());
} catch (NodeAccessException e) {
throw new ContentAccessException(e);
}
}
use of com.enonic.xp.schema.content.ContentType in project xp by enonic.
the class MoveContentCommandTest method move_fragment_to_the_same_site.
@Test
public void move_fragment_to_the_same_site() throws Exception {
final PropertyTree existingContentData = new PropertyTree();
existingContentData.addString("myData", "aaa");
final Site parentSite = createSite(existingContentData, ContentPath.ROOT);
final Content existingContent = createContent(existingContentData, parentSite.getPath(), ContentTypeName.fragment());
final Content existingFolder = createContent(existingContentData, parentSite.getPath(), ContentTypeName.folder());
MoveContentParams params = MoveContentParams.create().contentId(existingContent.getId()).parentContentPath(existingFolder.getPath()).build();
final MoveContentCommand command = MoveContentCommand.create(params).contentTypeService(this.contentTypeService).nodeService(this.nodeService).translator(this.translator).eventPublisher(this.eventPublisher).build();
final Node mockNode = Node.create().parentPath(NodePath.ROOT).build();
Mockito.when(nodeService.getById(NodeId.from(existingContent.getId()))).thenReturn(mockNode);
Mockito.when(nodeService.move(Mockito.any(MoveNodeParams.class))).thenReturn(mockNode);
Mockito.when(translator.fromNode(mockNode, true)).thenReturn(existingContent);
Mockito.when(translator.fromNode(mockNode, false)).thenReturn(existingContent);
final Node mockFolderNode = Node.create().parentPath(NodePath.ROOT).build();
Mockito.when(nodeService.getByPath(ContentNodeHelper.translateContentPathToNodePath(existingFolder.getPath()))).thenReturn(mockFolderNode);
Mockito.when(translator.fromNode(mockFolderNode, true)).thenReturn(existingFolder);
Mockito.when(translator.fromNode(mockFolderNode, false)).thenReturn(existingFolder);
final ContentType contentType = ContentType.create().name("folder").displayName("folder").setBuiltIn().setFinal(false).setAbstract(false).build();
Mockito.when(contentTypeService.getByName(new GetContentTypeParams().contentTypeName(existingFolder.getType()))).thenReturn(contentType);
// exercise
command.execute();
Mockito.verify(nodeService, Mockito.times(1)).move(Mockito.any(MoveNodeParams.class));
}
use of com.enonic.xp.schema.content.ContentType in project xp by enonic.
the class ProjectAccessSiteProcessorTest method testSupports.
@Test
public void testSupports() {
ContentType contentType = ContentType.create().superType(ContentTypeName.structured()).name(ContentTypeName.site()).build();
assertTrue(projectAccessSiteProcessor.supports(contentType));
contentType = ContentType.create().superType(ContentTypeName.structured()).name(ContentTypeName.media()).build();
assertFalse(projectAccessSiteProcessor.supports(contentType));
}
Aggregations