use of com.enonic.xp.schema.content.GetContentTypeParams in project xp by enonic.
the class ContentTypeServiceTest method testEmpty.
@Test
public void testEmpty() {
final ContentTypes types1 = this.service.getAll();
assertNotNull(types1);
assertEquals(22, types1.getSize());
final ContentTypes types2 = this.service.getByApplication(ApplicationKey.from("other"));
assertNotNull(types2);
assertEquals(0, types2.getSize());
final ContentType contentType = service.getByName(new GetContentTypeParams().contentTypeName("other:mytype"));
assertEquals(null, contentType);
}
use of com.enonic.xp.schema.content.GetContentTypeParams in project xp by enonic.
the class ContentTypeServiceTest method testSystemApplication.
@Test
public void testSystemApplication() {
ContentTypes contentTypes = this.service.getAll();
assertNotNull(contentTypes);
assertEquals(22, contentTypes.getSize());
ContentType contentType = service.getByName(new GetContentTypeParams().contentTypeName(ContentTypeName.folder()));
assertNotNull(contentType);
contentTypes = service.getByApplication(ApplicationKey.BASE);
assertNotNull(contentTypes);
assertEquals(contentTypes.getSize(), 5);
contentTypes = service.getByApplication(ApplicationKey.PORTAL);
assertNotNull(contentTypes);
assertEquals(contentTypes.getSize(), 4);
contentTypes = service.getByApplication(ApplicationKey.MEDIA_MOD);
assertNotNull(contentTypes);
assertEquals(contentTypes.getSize(), 13);
contentType = service.getByName(new GetContentTypeParams().contentTypeName(ContentTypeName.site()));
assertNotNull(contentType);
}
use of com.enonic.xp.schema.content.GetContentTypeParams 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.GetContentTypeParams in project xp by enonic.
the class ValidateContentDataCommand method execute.
ValidationErrors execute() {
final ContentType contentType = contentTypeService.getByName(new GetContentTypeParams().contentTypeName(contentTypeName));
Preconditions.checkArgument(contentType != null, "ContentType [%s] not found", contentTypeName);
final ContentValidatorParams validatorParams = contentValidatorParamsBuilder.contentType(contentType).build();
for (ContentValidator contentValidator : contentValidators) {
if (contentValidator.supports(contentTypeName)) {
contentValidator.validate(validatorParams, resultBuilder);
}
}
return this.resultBuilder.build();
}
use of com.enonic.xp.schema.content.GetContentTypeParams in project xp by enonic.
the class CreateContentCommandTest method createPageTemplateInRoot_fails.
@Test
public void createPageTemplateInRoot_fails() {
Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenAnswer(a -> BuiltinContentTypesAccessor.getContentType(((GetContentTypeParams) a.getArgument(0)).getContentTypeName()));
mockContentRootNode();
final CreateContentParams params = CreateContentParams.create().type(ContentTypeName.templateFolder()).name("folder").parent(ContentPath.ROOT).contentData(new PropertyTree()).displayName("displayName").build();
CreateContentCommand command = createContentCommand(params);
assertThrows(IllegalArgumentException.class, command::execute);
}
Aggregations