Search in sources :

Example 76 with ContentId

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

the class CreatedEventSyncCommand method doSync.

private void doSync(final ContentToSync content) {
    try {
        content.getSourceContext().runWith(() -> {
            if (contentService.contentExists(content.getSourceContent().getParentPath())) {
                final ContentId parentId = contentService.getByPath(content.getSourceContent().getParentPath()).getId();
                content.getTargetContext().runWith(() -> {
                    if (content.getSourceContent().getParentPath().isRoot()) {
                        syncRootContent(content);
                    } else if (contentService.contentExists(parentId)) {
                        syncChildContent(parentId, content);
                    }
                });
            }
        });
    } catch (ContentAlreadyExistsException e) {
        LOG.warn("content [{}] already exists.", content.getId());
    }
}
Also used : ContentAlreadyExistsException(com.enonic.xp.content.ContentAlreadyExistsException) ContentId(com.enonic.xp.content.ContentId)

Example 77 with ContentId

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

the class MoveContentCommand method doExecute.

private MoveContentsResult doExecute() {
    final ContentId contentId = params.getContentId();
    final Content sourceContent = getContent(contentId);
    final NodePath newParentPath = ContentNodeHelper.translateContentPathToNodePath(params.getParentContentPath());
    if (nodeService.nodeExists(NodePath.create(newParentPath, sourceContent.getName().toString()).build())) {
        throw new ContentAlreadyMovedException(String.format("Content with name [%s] is already a child of [%s]", sourceContent.getName(), params.getParentContentPath()), sourceContent.getPath());
    }
    validateParentChildRelations(params.getParentContentPath(), sourceContent.getType());
    final NodeId sourceNodeId = NodeId.from(contentId);
    final MoveNodeParams.Builder builder = MoveNodeParams.create().nodeId(sourceNodeId).parentNodePath(newParentPath).moveListener(this);
    if (params.stopInherit()) {
        builder.processor(new MoveContentProcessor());
    }
    final Node movedNode = nodeService.move(builder.build());
    final Content movedContent = translator.fromNode(movedNode, true);
    return MoveContentsResult.create().setContentName(movedContent.getDisplayName()).addMoved(movedContent.getId()).build();
}
Also used : MoveNodeParams(com.enonic.xp.node.MoveNodeParams) Content(com.enonic.xp.content.Content) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) ContentId(com.enonic.xp.content.ContentId) ContentAlreadyMovedException(com.enonic.xp.content.ContentAlreadyMovedException) NodePath(com.enonic.xp.node.NodePath)

Example 78 with ContentId

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

the class AbstractDataSerializerTest method createFragmentComponent.

protected 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();
    Mockito.when(contentService.getById(id)).thenReturn(fragmentContent);
    return FragmentComponent.create().fragment(id).build();
}
Also used : Content(com.enonic.xp.content.Content) ContentId(com.enonic.xp.content.ContentId)

Example 79 with ContentId

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

Example 80 with ContentId

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

the class PublishContentResultMapper method serializeFailedContent.

private void serializeFailedContent(final MapGenerator gen, final String name, final ContentIds contents) {
    gen.array(name);
    for (ContentId id : contents) {
        gen.value(id.toString());
    }
    for (ContentPath path : this.contentNotFound) {
        gen.value(path.toString());
    }
    gen.end();
}
Also used : ContentId(com.enonic.xp.content.ContentId) ContentPath(com.enonic.xp.content.ContentPath)

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