Search in sources :

Example 21 with ContentId

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

the class AbstractDataSerializerTest method createImageComponent.

protected ImageComponent createImageComponent(final String imageId, final String imageDisplayName, final PropertyTree imageConfig) {
    final ContentId id = ContentId.from(imageId);
    final Content imageContent = Content.create().name("someimage").displayName(imageDisplayName).parentPath(ContentPath.ROOT).build();
    Mockito.when(contentService.getById(id)).thenReturn(imageContent);
    return ImageComponent.create().image(id).config(imageConfig).build();
}
Also used : Content(com.enonic.xp.content.Content) ContentId(com.enonic.xp.content.ContentId)

Example 22 with ContentId

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

the class TestDataFixtures method createFragmentComponent.

private static FragmentComponent createFragmentComponent(final String fragmentId, final String fragmentDisplayName) {
    final ContentId id = ContentId.from(fragmentId);
    final Content fragmentContent = Content.create().name("somefragment").displayName(fragmentDisplayName).parentPath(ContentPath.ROOT).build();
    return FragmentComponent.create().fragment(id).build();
}
Also used : Content(com.enonic.xp.content.Content) ContentId(com.enonic.xp.content.ContentId)

Example 23 with ContentId

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

the class GetContentHandlerTest method getByIdInLayer.

@Test
public void getByIdInLayer() {
    final Content content = TestDataFixtures.newExampleLayerContentBuilder().build();
    final ContentId contentId = ContentId.from("mycontentId");
    Mockito.when(this.contentService.getById(contentId)).thenReturn(content);
    final ScriptValue result = runFunction("/test/GetContentHandlerTest.js", "getByIdInLayer");
    Assert.assertEquals(2, result.getMember("inherit").getArray().size());
    Assert.assertEquals("CONTENT", result.getMember("inherit").getArray().get(0).getValue());
    Assert.assertEquals("NAME", result.getMember("inherit").getArray().get(1).getValue());
    Assert.assertEquals("origin", result.getMember("originProject").getValue());
}
Also used : ScriptValue(com.enonic.xp.script.ScriptValue) Content(com.enonic.xp.content.Content) ContentId(com.enonic.xp.content.ContentId) Test(org.junit.jupiter.api.Test)

Example 24 with ContentId

use of com.enonic.xp.content.ContentId 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 25 with ContentId

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

the class ContentOutboundDependenciesIdsResolver method resolveOutboundDependenciesIds.

private ContentIds resolveOutboundDependenciesIds(final ContentId contentId) {
    final Content content = this.contentService.getById(contentId);
    final ContentIds.Builder contentIds = ContentIds.create();
    final PropertySet contentPageData = new PropertyTree().getRoot();
    if (content.getPage() != null) {
        contentDataSerializer.toPageData(content.getPage(), contentPageData);
    }
    final Stream<Property> extraDataDependencies = content.hasExtraData() ? content.getAllExtraData().stream().flatMap(extraData -> extraData.getData().getProperties(ValueTypes.REFERENCE).stream()) : Stream.empty();
    Stream.of(content.getData().getProperties(ValueTypes.REFERENCE).stream(), contentPageData.getProperties(ValueTypes.REFERENCE).stream(), extraDataDependencies).flatMap(s -> s).forEach(property -> {
        final String value = property.getValue().toString();
        if (!contentId.toString().equals(value) && !nullToEmpty(value).isBlank()) {
            contentIds.add(ContentId.from(value));
        }
    });
    if (content.getProcessedReferences() != null && content.getProcessedReferences().getSize() > 0) {
        contentIds.addAll(content.getProcessedReferences());
    }
    return contentIds.build();
}
Also used : ContentId(com.enonic.xp.content.ContentId) ContentService(com.enonic.xp.content.ContentService) Property(com.enonic.xp.data.Property) Stream(java.util.stream.Stream) ContentIds(com.enonic.xp.content.ContentIds) Strings.nullToEmpty(com.google.common.base.Strings.nullToEmpty) PropertySet(com.enonic.xp.data.PropertySet) Content(com.enonic.xp.content.Content) ContentDataSerializer(com.enonic.xp.core.impl.content.serializer.ContentDataSerializer) ValueTypes(com.enonic.xp.data.ValueTypes) PropertyTree(com.enonic.xp.data.PropertyTree) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ContentIds(com.enonic.xp.content.ContentIds) PropertySet(com.enonic.xp.data.PropertySet) Property(com.enonic.xp.data.Property)

Aggregations

ContentId (com.enonic.xp.content.ContentId)83 Content (com.enonic.xp.content.Content)34 Test (org.junit.jupiter.api.Test)33 PropertyTree (com.enonic.xp.data.PropertyTree)16 ContentPath (com.enonic.xp.content.ContentPath)14 ContentNotFoundException (com.enonic.xp.content.ContentNotFoundException)13 ContentIds (com.enonic.xp.content.ContentIds)11 PropertySet (com.enonic.xp.data.PropertySet)10 NodeId (com.enonic.xp.node.NodeId)9 BeforeEach (org.junit.jupiter.api.BeforeEach)8 ContentInheritType (com.enonic.xp.content.ContentInheritType)7 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)7 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)7 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)6 Context (com.enonic.xp.context.Context)6 DeleteContentParams (com.enonic.xp.content.DeleteContentParams)5 Node (com.enonic.xp.node.Node)5 Branch (com.enonic.xp.branch.Branch)4 ContentConstants (com.enonic.xp.content.ContentConstants)4 ContextBuilder (com.enonic.xp.context.ContextBuilder)4