Search in sources :

Example 26 with Contents

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();
}
Also used : Contents(com.enonic.xp.content.Contents)

Example 27 with Contents

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());
}
Also used : Contents(com.enonic.xp.content.Contents) Content(com.enonic.xp.content.Content) Nodes(com.enonic.xp.node.Nodes) Test(org.junit.jupiter.api.Test)

Example 28 with Contents

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());
}
Also used : GetContentByIdsParams(com.enonic.xp.content.GetContentByIdsParams) Contents(com.enonic.xp.content.Contents) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) DeleteContentsResult(com.enonic.xp.content.DeleteContentsResult) Test(org.junit.jupiter.api.Test)

Example 29 with Contents

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);
}
Also used : Contents(com.enonic.xp.content.Contents) Content(com.enonic.xp.content.Content)

Example 30 with 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);
}
Also used : FindContentIdsByQueryResult(com.enonic.xp.content.FindContentIdsByQueryResult) Contents(com.enonic.xp.content.Contents) GetContentByIdsParams(com.enonic.xp.content.GetContentByIdsParams) ContentQuery(com.enonic.xp.content.ContentQuery) Aggregations(com.enonic.xp.aggregation.Aggregations) HighlightedProperties(com.enonic.xp.highlight.HighlightedProperties) Instant(java.time.Instant) ContentId(com.enonic.xp.content.ContentId) StatsAggregation(com.enonic.xp.aggregation.StatsAggregation) BucketAggregation(com.enonic.xp.aggregation.BucketAggregation) Buckets(com.enonic.xp.aggregation.Buckets)

Aggregations

Contents (com.enonic.xp.content.Contents)41 Test (org.junit.jupiter.api.Test)30 Content (com.enonic.xp.content.Content)25 GetContentByIdsParams (com.enonic.xp.content.GetContentByIdsParams)16 ContentIds (com.enonic.xp.content.ContentIds)12 ContentPaths (com.enonic.xp.content.ContentPaths)7 PropertyTree (com.enonic.xp.data.PropertyTree)7 ContentId (com.enonic.xp.content.ContentId)5 ContentQuery (com.enonic.xp.content.ContentQuery)5 DeleteContentsResult (com.enonic.xp.content.DeleteContentsResult)5 FindContentByParentParams (com.enonic.xp.content.FindContentByParentParams)5 FindContentByParentResult (com.enonic.xp.content.FindContentByParentResult)5 FindContentIdsByQueryResult (com.enonic.xp.content.FindContentIdsByQueryResult)5 CreateContentParams (com.enonic.xp.content.CreateContentParams)4 Nodes (com.enonic.xp.node.Nodes)3 BucketAggregation (com.enonic.xp.aggregation.BucketAggregation)2 Buckets (com.enonic.xp.aggregation.Buckets)2 ApplicationKey (com.enonic.xp.app.ApplicationKey)2 ContentDependencies (com.enonic.xp.content.ContentDependencies)2 ContentIndexPath (com.enonic.xp.content.ContentIndexPath)2