use of com.enonic.xp.content.CreateContentParams in project xp by enonic.
the class CreateContentHandlerTest method createContentAutoGenerateNameWithExistingName.
@Test
public void createContentAutoGenerateNameWithExistingName() throws Exception {
when(this.contentService.create(any(CreateContentParams.class))).thenAnswer(mock -> createContent((CreateContentParams) mock.getArguments()[0]));
when(this.contentService.contentExists(Mockito.eq(ContentPath.from("/a/b/my-content")))).thenReturn(true);
when(this.contentService.contentExists(Mockito.eq(ContentPath.from("/a/b/my-content-1")))).thenReturn(true);
when(this.contentService.contentExists(Mockito.eq(ContentPath.from("/a/b/my-content-2")))).thenReturn(true);
final ContentType contentType = ContentType.create().name("test:myContentType").superType(ContentTypeName.structured()).build();
GetContentTypeParams getContentType = GetContentTypeParams.from(ContentTypeName.from("test:myContentType"));
when(this.contentTypeService.getByName(Mockito.eq(getContentType))).thenReturn(contentType);
runFunction("/test/CreateContentHandlerTest.js", "createContentAutoGenerateNameWithExistingName");
}
use of com.enonic.xp.content.CreateContentParams in project xp by enonic.
the class CreateContentHandlerTest method createContentAutoGenerateName.
@Test
public void createContentAutoGenerateName() throws Exception {
when(this.contentService.create(any(CreateContentParams.class))).thenAnswer(mock -> createContent((CreateContentParams) mock.getArguments()[0]));
final ContentType contentType = ContentType.create().name("test:myContentType").superType(ContentTypeName.structured()).build();
GetContentTypeParams getContentType = GetContentTypeParams.from(ContentTypeName.from("test:myContentType"));
when(this.contentTypeService.getByName(Mockito.eq(getContentType))).thenReturn(contentType);
runFunction("/test/CreateContentHandlerTest.js", "createContentAutoGenerateName");
}
use of com.enonic.xp.content.CreateContentParams in project xp by enonic.
the class CreateMediaCommand method doExecute.
private Content doExecute() {
final MediaInfo mediaInfo = mediaInfoService.parseMediaInfo(params.getByteSource());
if ((params.getMimeType() == null || isBinaryContentType(params.getMimeType())) && mediaInfo.getMediaType() != null) {
params.mimeType(mediaInfo.getMediaType());
}
Preconditions.checkNotNull(params.getMimeType(), "Unable to resolve media type");
final ContentTypeName resolvedTypeFromMimeType = ContentTypeFromMimeTypeResolver.resolve(params.getMimeType());
final ContentTypeName type = resolvedTypeFromMimeType != null ? resolvedTypeFromMimeType : isExecutableContentType(params.getMimeType(), params.getName()) ? ContentTypeName.executableMedia() : ContentTypeName.unknownMedia();
final PropertyTree data = new PropertyTree();
new MediaFormDataBuilder().type(type).attachment(params.getName()).focalX(params.getFocalX()).focalY(params.getFocalY()).caption(params.getCaption()).artist(params.getArtist()).copyright(params.getCopyright()).tags(params.getTags()).build(data);
final CreateAttachment mediaAttachment = CreateAttachment.create().name(params.getName()).mimeType(params.getMimeType()).label("source").byteSource(params.getByteSource()).text(type.isTextualMedia() ? mediaInfo.getTextContent() : "").build();
final CreateContentParams createContentParams = CreateContentParams.create().name(params.getName()).parent(params.getParent()).requireValid(true).type(type).displayName(trimExtension(params.getName())).contentData(data).createAttachments(CreateAttachments.from(mediaAttachment)).inheritPermissions(true).build();
final CreateContentCommand createCommand = CreateContentCommand.create(this).mediaInfo(mediaInfo).params(createContentParams).siteService(this.siteService).xDataService(this.xDataService).formDefaultValuesProcessor(this.formDefaultValuesProcessor).pageDescriptorService(this.pageDescriptorService).partDescriptorService(this.partDescriptorService).layoutDescriptorService(this.layoutDescriptorService).contentDataSerializer(this.contentDataSerializer).allowUnsafeAttachmentNames(this.allowUnsafeAttachmentNames).build();
return createCommand.execute();
}
use of com.enonic.xp.content.CreateContentParams in project xp by enonic.
the class ImageContentProcessor method processCreate.
@Override
public ProcessCreateResult processCreate(final ProcessCreateParams params) {
final CreateContentParams createContentParams = params.getCreateContentParams();
final MediaInfo mediaInfo = params.getMediaInfo();
final CreateAttachments originalAttachments = createContentParams.getCreateAttachments();
Preconditions.checkArgument(originalAttachments.getSize() == 1, "Expected only one attachment");
final CreateAttachment sourceAttachment = originalAttachments.first();
final XDatas contentXDatas = getXDatas(createContentParams.getType());
ExtraDatas extraDatas = null;
if (mediaInfo != null) {
extraDatas = extractMetadata(mediaInfo, contentXDatas, sourceAttachment);
}
final CreateAttachments.Builder builder = CreateAttachments.create();
builder.add(sourceAttachment);
return new ProcessCreateResult(CreateContentParams.create(createContentParams).createAttachments(builder.build()).extraDatas(extraDatas).build());
}
use of com.enonic.xp.content.CreateContentParams in project xp by enonic.
the class CreateContentCommandTest method unnamedContent.
@Test
public void unnamedContent() {
final CreateContentParams params = createContentParams().name((ContentName) null).displayName(null).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();
assertTrue(createdContent.getName().isUnnamed());
assertEquals("", createdContent.getDisplayName());
}
Aggregations