Search in sources :

Example 1 with ContentDependenciesAggregation

use of com.enonic.xp.content.ContentDependenciesAggregation in project xp by enonic.

the class ContentDependenciesResolver method resolveOutboundDependenciesAggregation.

private Collection<ContentDependenciesAggregation> resolveOutboundDependenciesAggregation(final ContentId contentId) {
    final Map<ContentTypeName, Long> aggregationJsonMap = new HashMap<>();
    final Contents contents = this.contentService.getByIds(new GetContentByIdsParams(this.contentService.getOutboundDependencies(contentId)));
    contents.forEach(existingContent -> {
        final ContentTypeName contentTypeName = existingContent.getType();
        final Long count = aggregationJsonMap.containsKey(contentTypeName) ? aggregationJsonMap.get(contentTypeName) + 1 : 1;
        aggregationJsonMap.put(contentTypeName, count);
    });
    return aggregationJsonMap.entrySet().stream().map(entry -> new ContentDependenciesAggregation(entry.getKey(), entry.getValue())).collect(toList());
}
Also used : IdFilter(com.enonic.xp.query.filter.IdFilter) BucketAggregation(com.enonic.xp.aggregation.BucketAggregation) ContentService(com.enonic.xp.content.ContentService) ContentIndexPath(com.enonic.xp.content.ContentIndexPath) FindContentIdsByQueryResult(com.enonic.xp.content.FindContentIdsByQueryResult) Collection(java.util.Collection) HashMap(java.util.HashMap) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName) ContentDependenciesAggregation(com.enonic.xp.content.ContentDependenciesAggregation) HashSet(java.util.HashSet) ContentQuery(com.enonic.xp.content.ContentQuery) ContentId(com.enonic.xp.content.ContentId) Collectors.toList(java.util.stream.Collectors.toList) GetContentByIdsParams(com.enonic.xp.content.GetContentByIdsParams) Contents(com.enonic.xp.content.Contents) BooleanFilter(com.enonic.xp.query.filter.BooleanFilter) TermsAggregationQuery(com.enonic.xp.query.aggregation.TermsAggregationQuery) Map(java.util.Map) ContentDependencies(com.enonic.xp.content.ContentDependencies) ContentDependenciesAggregation(com.enonic.xp.content.ContentDependenciesAggregation) Contents(com.enonic.xp.content.Contents) GetContentByIdsParams(com.enonic.xp.content.GetContentByIdsParams) HashMap(java.util.HashMap) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName)

Example 2 with ContentDependenciesAggregation

use of com.enonic.xp.content.ContentDependenciesAggregation in project xp by enonic.

the class ContentDependenciesResolverTest method resolve_inbound_dependencies.

@Test
public void resolve_inbound_dependencies() throws Exception {
    final Content content = createContent("folderRefContent1", new PropertyTree(), ContentTypeName.folder());
    final FindContentIdsByQueryResult findContentByQueryResult = FindContentIdsByQueryResult.create().aggregations(Aggregations.from(BucketAggregation.bucketAggregation("type").buckets(Buckets.create().add(Bucket.create().key("portal:site").docCount(2).build()).add(Bucket.create().key("base:folder").docCount(1).build()).build()).build())).build();
    Mockito.when(contentService.getById(content.getId())).thenReturn(content);
    Mockito.when(contentService.getByIds(Mockito.any())).thenReturn(Contents.empty());
    Mockito.when(contentService.find(Mockito.isA(ContentQuery.class))).thenReturn(findContentByQueryResult);
    Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenReturn(ContentType.create().name("mycontenttype").icon(Icon.from(new byte[] { 1 }, "mime", Instant.now())).setBuiltIn(true).build());
    final ContentDependencies result = resolver.resolve(content.getId());
    assertEquals(result.getInbound().size(), 2);
    final ContentDependenciesAggregation siteAggregation = (ContentDependenciesAggregation) result.getInbound().toArray()[0];
    assertEquals(siteAggregation.getType(), ContentTypeName.site());
    assertEquals(siteAggregation.getCount(), 2);
    final ContentDependenciesAggregation folderAggregation = (ContentDependenciesAggregation) result.getInbound().toArray()[1];
    assertEquals(folderAggregation.getType(), ContentTypeName.folder());
    assertEquals(folderAggregation.getCount(), 1);
}
Also used : FindContentIdsByQueryResult(com.enonic.xp.content.FindContentIdsByQueryResult) ContentDependenciesAggregation(com.enonic.xp.content.ContentDependenciesAggregation) GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) ContentQuery(com.enonic.xp.content.ContentQuery) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ContentDependencies(com.enonic.xp.content.ContentDependencies) Test(org.junit.jupiter.api.Test)

Example 3 with ContentDependenciesAggregation

use of com.enonic.xp.content.ContentDependenciesAggregation in project xp by enonic.

the class ContentDependenciesResolverTest method resolve_outbound_with_missing_dependency.

@Test
public void resolve_outbound_with_missing_dependency() throws Exception {
    final PropertyTree data = new PropertyTree();
    final Content folderRefContent1 = createContent("folderRefContent1", data, ContentTypeName.folder());
    final Content folderRefContent2 = createContent("folderRefContent2", data, ContentTypeName.folder());
    data.addReference("myRef1", Reference.from(folderRefContent1.getId().toString()));
    data.addReference("myRef2", Reference.from(folderRefContent2.getId().toString()));
    data.addReference("myRef3", Reference.from("some-id"));
    final Content content = createContent("content", data, ContentTypeName.site());
    final FindContentIdsByQueryResult findContentByQueryResult = FindContentIdsByQueryResult.create().aggregations(Aggregations.from(BucketAggregation.bucketAggregation("type").buckets(Buckets.create().build()).build())).build();
    Mockito.when(contentService.getByIds(Mockito.any())).thenReturn(Contents.from(folderRefContent1, folderRefContent2));
    Mockito.when(contentService.getById(content.getId())).thenReturn(content);
    Mockito.when(contentService.find(Mockito.isA(ContentQuery.class))).thenReturn(findContentByQueryResult);
    Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenReturn(ContentType.create().name("mycontenttype").icon(Icon.from(new byte[] { 1 }, "mime", Instant.now())).setBuiltIn(true).build());
    final ContentDependencies result = resolver.resolve(content.getId());
    assertEquals(result.getOutbound().size(), 1);
    final ContentDependenciesAggregation folderAggregation = (ContentDependenciesAggregation) result.getOutbound().toArray()[0];
    assertEquals(folderAggregation.getType(), ContentTypeName.folder());
    assertEquals(folderAggregation.getCount(), 2);
}
Also used : FindContentIdsByQueryResult(com.enonic.xp.content.FindContentIdsByQueryResult) ContentDependenciesAggregation(com.enonic.xp.content.ContentDependenciesAggregation) GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) ContentQuery(com.enonic.xp.content.ContentQuery) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ContentDependencies(com.enonic.xp.content.ContentDependencies) Test(org.junit.jupiter.api.Test)

Example 4 with ContentDependenciesAggregation

use of com.enonic.xp.content.ContentDependenciesAggregation in project xp by enonic.

the class ContentDependenciesResolverTest method resolve_outbound_dependencies.

@Test
public void resolve_outbound_dependencies() 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", data, ContentTypeName.site());
    final FindContentIdsByQueryResult findContentByQueryResult = FindContentIdsByQueryResult.create().aggregations(Aggregations.from(BucketAggregation.bucketAggregation("type").buckets(Buckets.create().build()).build())).build();
    Mockito.when(contentService.getByIds(Mockito.any())).thenReturn(Contents.from(folderRefContent1, folderRefContent2, siteRefContent1));
    Mockito.when(contentService.getById(content.getId())).thenReturn(content);
    Mockito.when(contentService.find(Mockito.isA(ContentQuery.class))).thenReturn(findContentByQueryResult);
    Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenReturn(ContentType.create().name("mycontenttype").icon(Icon.from(new byte[] { 1 }, "mime", Instant.now())).setBuiltIn(true).build());
    final ContentDependencies result = resolver.resolve(content.getId());
    assertEquals(result.getOutbound().size(), 2);
    final ContentDependenciesAggregation siteAggregation = (ContentDependenciesAggregation) result.getOutbound().toArray()[0];
    assertEquals(siteAggregation.getType(), ContentTypeName.site());
    assertEquals(siteAggregation.getCount(), 1);
    final ContentDependenciesAggregation folderAggregation = (ContentDependenciesAggregation) result.getOutbound().toArray()[1];
    assertEquals(folderAggregation.getType(), ContentTypeName.folder());
    assertEquals(folderAggregation.getCount(), 2);
}
Also used : FindContentIdsByQueryResult(com.enonic.xp.content.FindContentIdsByQueryResult) ContentDependenciesAggregation(com.enonic.xp.content.ContentDependenciesAggregation) GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) ContentQuery(com.enonic.xp.content.ContentQuery) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ContentDependencies(com.enonic.xp.content.ContentDependencies) Test(org.junit.jupiter.api.Test)

Aggregations

ContentDependencies (com.enonic.xp.content.ContentDependencies)4 ContentDependenciesAggregation (com.enonic.xp.content.ContentDependenciesAggregation)4 ContentQuery (com.enonic.xp.content.ContentQuery)4 FindContentIdsByQueryResult (com.enonic.xp.content.FindContentIdsByQueryResult)4 Content (com.enonic.xp.content.Content)3 PropertyTree (com.enonic.xp.data.PropertyTree)3 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)3 Test (org.junit.jupiter.api.Test)3 BucketAggregation (com.enonic.xp.aggregation.BucketAggregation)1 ContentId (com.enonic.xp.content.ContentId)1 ContentIndexPath (com.enonic.xp.content.ContentIndexPath)1 ContentService (com.enonic.xp.content.ContentService)1 Contents (com.enonic.xp.content.Contents)1 GetContentByIdsParams (com.enonic.xp.content.GetContentByIdsParams)1 TermsAggregationQuery (com.enonic.xp.query.aggregation.TermsAggregationQuery)1 BooleanFilter (com.enonic.xp.query.filter.BooleanFilter)1 IdFilter (com.enonic.xp.query.filter.IdFilter)1 ContentTypeName (com.enonic.xp.schema.content.ContentTypeName)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1