use of com.enonic.xp.content.Contents in project xp by enonic.
the class ContentServiceImpl method undoPendingDelete.
@Override
public int undoPendingDelete(final UndoPendingDeleteContentParams params) {
final Contents affectedContents = UndoPendingDeleteContentCommand.create().nodeService(this.nodeService).contentTypeService(this.contentTypeService).translator(this.translator).eventPublisher(this.eventPublisher).params(params).build().execute();
contentAuditLogSupport.undoPendingDelete(params, affectedContents);
return affectedContents.getSize();
}
use of com.enonic.xp.content.Contents in project xp by enonic.
the class ContentNodeTranslatorTest method testFromNodesNotResolvingChildren.
@Test
public void testFromNodesNotResolvingChildren() throws Exception {
final Nodes nodes = createNodes();
final Contents contents = this.contentNodeTranslator.fromNodes(nodes, false);
assertEquals(3, contents.getSize());
final Content content1 = contents.getContentById(ContentId.from(ID_1.toString()));
final Content content3 = contents.getContentById(ContentId.from(ID_3.toString()));
final Content content2 = contents.getContentById(ContentId.from(ID_2.toString()));
assertFalse(content1.hasChildren());
assertFalse(content2.hasChildren());
assertFalse(content3.hasChildren());
}
use of com.enonic.xp.content.Contents in project xp by enonic.
the class ContentServiceImplTest_delete method create_delete_content_with_children.
@Test
public void create_delete_content_with_children() 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 createChild2ContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("Child2 Content").parent(content.getPath()).type(ContentTypeName.folder()).build();
final Content child2Content = this.contentService.create(createChild2ContentParams);
final CreateContentParams createSubChildContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("SubChild Content").parent(child1Content.getPath()).type(ContentTypeName.folder()).build();
final Content subChildContent = this.contentService.create(createSubChildContentParams);
refresh();
// Deletes the content
final DeleteContentsResult deletedContents = this.contentService.deleteWithoutFetch(DeleteContentParams.create().contentPath(content.getPath()).build());
assertNotNull(deletedContents);
assertEquals(4, deletedContents.getDeletedContents().getSize());
// Checks that the content and the children are deleted
final GetContentByIdsParams getContentByIdsParams = new GetContentByIdsParams(ContentIds.from(content.getId(), child1Content.getId(), child2Content.getId(), subChildContent.getId()));
final Contents foundContents = this.contentService.getByIds(getContentByIdsParams);
assertEquals(0, foundContents.getSize());
}
use of com.enonic.xp.content.Contents in project xp by enonic.
the class ApplicationInfoServiceImplTest method mockReferences.
private void mockReferences(final ApplicationKey applicationKey) {
final Content content1 = Content.create().id(ContentId.from("id1")).name("name1").displayName("My Content 1").parentPath(ContentPath.from("/a/b")).modifier(PrincipalKey.from("user:system:admin")).modifiedTime(Instant.ofEpochSecond(0)).creator(PrincipalKey.from("user:system:admin")).createdTime(Instant.ofEpochSecond(0)).build();
final Content content2 = Content.create().id(ContentId.from("id2")).name("name2").displayName("My Content 2").parentPath(ContentPath.from("/a/c")).modifier(PrincipalKey.from("user:system:admin")).modifiedTime(Instant.ofEpochSecond(0)).creator(PrincipalKey.from("user:system:admin")).createdTime(Instant.ofEpochSecond(0)).build();
final Contents contents = Contents.from(content1, content2);
Mockito.when(this.contentService.findByApplicationKey(applicationKey)).thenReturn(contents);
}
use of com.enonic.xp.content.Contents in project xp by enonic.
the class QueryContentHandlerTest method setupQuery.
private void setupQuery(final int count, final boolean aggs, final boolean addHighlight) {
final Contents contents = TestDataFixtures.newContents(count);
final Instant t1 = Instant.parse("2014-09-01T00:00:00.00Z");
final Instant t2 = Instant.parse("2014-10-01T00:00:00.00Z");
final Instant t3 = Instant.parse("2014-11-01T00:00:00.00Z");
final Buckets buckets1 = Buckets.create().add(Bucket.create().key("male").docCount(10).build()).add(Bucket.create().key("female").docCount(12).build()).build();
final Buckets buckets2 = Buckets.create().add(Bucket.create().key("2014-01").docCount(8).build()).add(Bucket.create().key("2014-02").docCount(10).build()).add(Bucket.create().key("2014-03").docCount(12).build()).build();
final Buckets buckets3 = Buckets.create().add(NumericRangeBucket.create().key("a").docCount(2).to(50).build()).add(NumericRangeBucket.create().key("b").docCount(4).from(50).to(100).build()).add(NumericRangeBucket.create().key("c").docCount(4).from(100).build()).build();
final Buckets buckets4 = Buckets.create().add(DateRangeBucket.create().from(t1).docCount(2).key("date range bucket key").build()).add(DateRangeBucket.create().to(t1).from(t2).docCount(5).build()).add(DateRangeBucket.create().to(t3).docCount(7).build()).build();
final BucketAggregation aggr1 = BucketAggregation.bucketAggregation("genders").buckets(buckets1).build();
final BucketAggregation aggr2 = BucketAggregation.bucketAggregation("by_month").buckets(buckets2).build();
final BucketAggregation aggr3 = BucketAggregation.bucketAggregation("price_ranges").buckets(buckets3).build();
final BucketAggregation aggr4 = BucketAggregation.bucketAggregation("my_date_range").buckets(buckets4).build();
final StatsAggregation aggr5 = StatsAggregation.create("item_count").avg(3).max(5).min(1).sum(15).count(5).build();
final Aggregations aggregations = Aggregations.from(aggr1, aggr2, aggr3, aggr4, aggr5);
final Map<ContentId, HighlightedProperties> highlight = Map.of(ContentId.from("123"), HighlightedProperties.create().add(HighlightedProperty.create().name("property1").addFragment("fragment1_1").addFragment("fragment1_2").build()).build(), ContentId.from("456"), HighlightedProperties.create().add(HighlightedProperty.create().name("property2").addFragment("fragment2_1").addFragment("fragment2_2").build()).build());
final FindContentIdsByQueryResult findResult = FindContentIdsByQueryResult.create().hits(contents.getSize()).totalHits(20).contents(contents.getIds()).aggregations(aggs ? aggregations : null).highlight(addHighlight ? highlight : null).build();
Mockito.when(this.contentService.find(Mockito.isA(ContentQuery.class))).thenReturn(findResult);
Mockito.when(this.contentService.getByIds(Mockito.isA(GetContentByIdsParams.class))).thenReturn(contents);
}
Aggregations