use of com.enonic.xp.content.ContentIds in project xp by enonic.
the class DuplicateContentCommand method doExecute.
private DuplicateContentsResult doExecute() {
final NodeId sourceNodeId = NodeId.from(params.getContentId());
final Node sourceNode = nodeService.getById(sourceNodeId);
if (sourceNode == null) {
throw new IllegalArgumentException(String.format("Content with id [%s] not found", params.getContentId()));
}
final DuplicateNodeParams duplicateNodeParams = DuplicateNodeParams.create().duplicateListener(this).nodeId(sourceNodeId).dataProcessor(new DuplicateContentProcessor()).includeChildren(params.getIncludeChildren()).build();
final Node duplicatedNode = nodeService.duplicate(duplicateNodeParams);
final Content duplicatedContent = translator.fromNode(duplicatedNode, true);
final ContentIds childrenIds = params.getIncludeChildren() ? getAllChildren(duplicatedContent) : ContentIds.empty();
return DuplicateContentsResult.create().setSourceContentPath(ContentNodeHelper.translateNodePathToContentPath(sourceNode.path())).setContentName(duplicatedContent.getDisplayName()).addDuplicated(duplicatedContent.getId()).addDuplicated(childrenIds).build();
}
use of com.enonic.xp.content.ContentIds in project xp by enonic.
the class ContentQueryNodeQueryTranslator method processReferenceIds.
private static void processReferenceIds(final ContentQuery contentQuery, final NodeQuery.Builder builder) {
final ContentIds contentIds = contentQuery.getFilterContentIds();
if (contentIds != null && contentIds.isNotEmpty()) {
final IdFilter.Builder contentTypeFilterBuilder = IdFilter.create().fieldName(ContentIndexPath.ID.getPath()).values(contentIds.asStrings()).setCache(true);
builder.addQueryFilter(contentTypeFilterBuilder.build());
}
}
use of com.enonic.xp.content.ContentIds in project xp by enonic.
the class ContentServiceImplTest_delete method create_delete_content.
@Test
public void create_delete_content() throws Exception {
// Creates a content
final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").name("myContent").parent(ContentPath.ROOT).type(ContentTypeName.folder()).build();
final Content content = this.contentService.create(createContentParams);
// Deletes the content
final DeleteContentParams deleteContentParams = DeleteContentParams.create().contentPath(content.getPath()).build();
final DeleteContentsResult deletedContents = this.contentService.deleteWithoutFetch(deleteContentParams);
assertNotNull(deletedContents);
assertEquals(1, deletedContents.getDeletedContents().getSize());
assertEquals(content.getId(), deletedContents.getDeletedContents().first());
// Checks that the content is deleted
final ContentIds contentIds = ContentIds.from(content.getId());
final GetContentByIdsParams getContentByIdsParams = new GetContentByIdsParams(contentIds);
final Contents foundContents = this.contentService.getByIds(getContentByIdsParams);
assertEquals(0, foundContents.getSize());
}
use of com.enonic.xp.content.ContentIds in project xp by enonic.
the class QueryContentHandler method convert.
private ContentsResultMapper convert(final FindContentIdsByQueryResult findQueryResult) {
final ContentIds contentIds = findQueryResult.getContentIds();
final Contents contents;
if (contentIds.isEmpty()) {
contents = Contents.empty();
} else {
contents = this.contentService.getByIds(new GetContentByIdsParams(contentIds));
}
return new ContentsResultMapper(contents, findQueryResult.getTotalHits(), findQueryResult.getAggregations(), findQueryResult.getHighlight(), findQueryResult.getSort(), findQueryResult.getScore());
}
use of com.enonic.xp.content.ContentIds in project xp by enonic.
the class ContentOutboundDependenciesIdsResolverTest method resolve_outbound_from_xdata.
@Test
public void resolve_outbound_from_xdata() throws Exception {
final PropertyTree data = new PropertyTree();
final Content folderRefContent1 = createContent("folderRefContent1", data, ContentTypeName.folder());
final Content folderRefContent2 = createContent("folderRefContent2", data, ContentTypeName.folder());
final Content siteRefContent1 = createContent("siteRefContent1", data, ContentTypeName.site());
data.addReference("myRef1", Reference.from(folderRefContent1.getId().toString()));
data.addReference("myRef2", Reference.from(folderRefContent2.getId().toString()));
data.addReference("myRef3", Reference.from(siteRefContent1.getId().toString()));
data.addReference("refToMyself", Reference.from("contentId"));
final Content content = createContent("contentId", new PropertyTree(), ContentTypeName.site(), ExtraDatas.create().add(new ExtraData(XDataName.from("x-data"), data)).build());
Mockito.when(contentService.getByIds(Mockito.any())).thenReturn(Contents.from(folderRefContent1, folderRefContent2, siteRefContent1));
Mockito.when(contentService.getById(content.getId())).thenReturn(content);
final ContentIds result = resolver.resolve(content.getId());
assertEquals(result.getSize(), 3);
assertTrue(result.contains(folderRefContent1.getId()));
assertTrue(result.contains(folderRefContent2.getId()));
assertTrue(result.contains(siteRefContent1.getId()));
}
Aggregations