use of com.enonic.xp.content.CreateContentParams in project xp by enonic.
the class ContentServiceImplTest_duplicate method some_metadata_reset_on_duplicate.
@Test
public void some_metadata_reset_on_duplicate() throws Exception {
final User otherUser = User.create().key(PrincipalKey.ofUser(IdProviderKey.system(), "fisk")).login("fisk").build();
final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("rootContent").parent(ContentPath.ROOT).type(ContentTypeName.folder()).permissions(AccessControlList.create().add(AccessControlEntry.create().principal(otherUser.getKey()).allowAll().build()).build()).build();
final Content rootContent = this.contentService.create(createContentParams);
final Context duplicateContext = ContextBuilder.from(ContextAccessor.current()).authInfo(AuthenticationInfo.create().user(otherUser).principals(RoleKeys.CONTENT_MANAGER_ADMIN).build()).build();
final Content duplicateContent = duplicateContext.callWith(() -> doDuplicateContent(rootContent));
assertTrue(rootContent.getModifiedTime().isBefore(duplicateContent.getModifiedTime()));
assertTrue(rootContent.getCreatedTime().isBefore(duplicateContent.getCreatedTime()));
assertEquals(otherUser.getKey(), duplicateContent.getModifier());
assertEquals(otherUser.getKey(), duplicateContent.getOwner());
assertEquals(otherUser.getKey(), duplicateContent.getCreator());
}
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 ContentServiceImplTest_create method create_content_generated_properties.
@Test
public void create_content_generated_properties() throws Exception {
final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").parent(ContentPath.ROOT).type(ContentTypeName.folder()).build();
final Content content = this.contentService.create(createContentParams);
assertNotNull(content.getName());
assertEquals("this-is-my-content", content.getName().toString());
assertNotNull(content.getCreatedTime());
assertNotNull(content.getCreator());
assertNotNull(content.getModifiedTime());
assertNotNull(content.getModifier());
assertNotNull(content.getChildOrder());
assertEquals(ContentConstants.DEFAULT_CHILD_ORDER, content.getChildOrder());
final Content storedContent = this.contentService.getById(content.getId());
assertNotNull(storedContent.getName());
assertEquals("this-is-my-content", storedContent.getName().toString());
assertNotNull(storedContent.getCreatedTime());
assertNotNull(storedContent.getCreator());
assertNotNull(storedContent.getModifiedTime());
assertNotNull(storedContent.getModifier());
assertNotNull(storedContent.getChildOrder());
assertEquals(ContentConstants.DEFAULT_CHILD_ORDER, storedContent.getChildOrder());
}
use of com.enonic.xp.content.CreateContentParams in project xp by enonic.
the class ContentServiceImplTest_delete method publish_pending_content_with_child_moved_inside_the_tree.
@Test
public void publish_pending_content_with_child_moved_inside_the_tree() throws Exception {
// Creates a content with children
final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("Root Content").parent(ContentPath.ROOT).type(ContentTypeName.folder()).build();
final Content content = this.contentService.create(createContentParams);
final CreateContentParams createChild1ContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("Child1 Content").parent(content.getPath()).type(ContentTypeName.folder()).build();
final Content child1Content = this.contentService.create(createChild1ContentParams);
final CreateContentParams createMovedContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("Content to move").parent(child1Content.getPath()).type(ContentTypeName.folder()).build();
final Content contentToMove = this.contentService.create(createMovedContentParams);
refresh();
this.contentService.publish(PushContentParams.create().contentIds(ContentIds.from(contentToMove.getId())).target(WS_OTHER).build());
refresh();
this.contentService.move(MoveContentParams.create().contentId(contentToMove.getId()).parentContentPath(content.getPath()).build());
refresh();
DeleteContentsResult result = this.contentService.deleteWithoutFetch(DeleteContentParams.create().contentPath(content.getPath()).build());
assertEquals(3, result.getPendingContents().getSize());
final PublishContentResult publishResult = this.contentService.publish(PushContentParams.create().contentIds(ContentIds.from(content.getId())).target(WS_OTHER).includeDependencies(false).build());
assertEquals(3, publishResult.getUnpublishedContents().getSize());
assertEquals(3, publishResult.getDeletedContents().getSize());
}
use of com.enonic.xp.content.CreateContentParams in project xp by enonic.
the class ContentServiceImplTest_delete method publish_pending_content_with_excluded_child_moved_out_of_tree.
@Test
public void publish_pending_content_with_excluded_child_moved_out_of_tree() throws Exception {
// Creates a content with children
final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("Root Content").parent(ContentPath.ROOT).type(ContentTypeName.folder()).build();
final Content content = this.contentService.create(createContentParams);
final CreateContentParams createChild1ContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("Child1 Content").parent(content.getPath()).type(ContentTypeName.folder()).build();
final Content child1Content = this.contentService.create(createChild1ContentParams);
final CreateContentParams createMovedContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("Content to move").parent(child1Content.getPath()).type(ContentTypeName.folder()).build();
final Content contentToMove = this.contentService.create(createMovedContentParams);
refresh();
this.contentService.publish(PushContentParams.create().contentIds(ContentIds.from(contentToMove.getId())).target(WS_OTHER).build());
refresh();
this.contentService.move(MoveContentParams.create().contentId(contentToMove.getId()).parentContentPath(ContentPath.ROOT).build());
refresh();
DeleteContentsResult result = this.contentService.deleteWithoutFetch(DeleteContentParams.create().contentPath(content.getPath()).build());
assertEquals(2, result.getPendingContents().getSize());
final PublishContentResult publishResult = this.contentService.publish(PushContentParams.create().contentIds(ContentIds.from(content.getId())).target(WS_OTHER).includeDependencies(false).excludedContentIds(ContentIds.from(contentToMove.getId())).build());
assertEquals(0, publishResult.getPushedContents().getSize());
assertEquals(2, publishResult.getDeletedContents().getSize());
assertEquals(3, publishResult.getUnpublishedContents().getSize());
}
Aggregations