Search in sources :

Example 6 with FindContentByQueryResult

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

the class ContentServiceImplTest_find method test_publish_expired_master.

@Test
public void test_publish_expired_master() throws Exception {
    authorizedMasterContext().callWith(() -> {
        final FindContentByQueryResult result = createAndFindContent(ContentPublishInfo.create().from(Instant.now().minus(Duration.ofDays(1))).to(Instant.now().minus(Duration.ofDays(1))).build());
        assertEquals(0, result.getTotalHits());
        return null;
    });
}
Also used : FindContentByQueryResult(com.enonic.xp.content.FindContentByQueryResult) Test(org.junit.jupiter.api.Test)

Example 7 with FindContentByQueryResult

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

the class ContentServiceImplTest_find method test_publish_expired_draft.

@Test
public void test_publish_expired_draft() throws Exception {
    final FindContentByQueryResult result = createAndFindContent(ContentPublishInfo.create().from(Instant.now().minus(Duration.ofDays(1))).to(Instant.now().minus(Duration.ofDays(1))).build());
    assertEquals(1, result.getTotalHits());
}
Also used : FindContentByQueryResult(com.enonic.xp.content.FindContentByQueryResult) Test(org.junit.jupiter.api.Test)

Example 8 with FindContentByQueryResult

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

the class ContentServiceImplTest_find method test_published_master.

@Test
public void test_published_master() throws Exception {
    authorizedMasterContext().callWith(() -> {
        final FindContentByQueryResult result = createAndFindContent(ContentPublishInfo.create().from(Instant.now().minus(Duration.ofDays(1))).to(Instant.now().plus(Duration.ofDays(1))).build());
        assertEquals(1, result.getTotalHits());
        return null;
    });
}
Also used : FindContentByQueryResult(com.enonic.xp.content.FindContentByQueryResult) Test(org.junit.jupiter.api.Test)

Example 9 with FindContentByQueryResult

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

the class CheckContentValidityCommand method execute.

public ContentValidityResult execute() {
    if (this.contentIds.getSize() == 0) {
        return ContentValidityResult.empty();
    }
    // valid == false
    final Filter notValid = ValueFilter.create().fieldName(ContentPropertyNames.VALID).addValue(ValueFactory.newBoolean(false)).build();
    // workflow != null && workflow != READY
    final Filter notReady = BooleanFilter.create().must(ExistsFilter.create().fieldName(WORKFLOW_STATE_FIELD).build()).mustNot(ValueFilter.create().fieldName(WORKFLOW_STATE_FIELD).addValues(WorkflowState.READY.toString()).build()).build();
    // valid == false OR (workflow != null && workflow != READY)
    final Filter filter = BooleanFilter.create().should(notValid).should(notReady).build();
    final ContentQuery query = ContentQuery.create().queryFilter(filter).queryFilter(IdFilter.create().fieldName(ContentIndexPath.ID.getPath()).values(contentIds.asStrings()).build()).size(-1).build();
    final FindContentByQueryResult result = FindContentByQueryCommand.create().params(FindContentByQueryParams.create().contentQuery(query).populateChildren(false).build()).contentTypeService(this.contentTypeService).eventPublisher(this.eventPublisher).nodeService(this.nodeService).translator(this.translator).build().execute();
    ContentIds.Builder invalidContentIds = ContentIds.create();
    ContentIds.Builder notReadyContentIds = ContentIds.create();
    result.getContents().forEach(content -> {
        if (!content.isValid()) {
            invalidContentIds.add(content.getId());
        }
        if (!content.getWorkflowInfo().getState().equals(WorkflowState.READY)) {
            notReadyContentIds.add(content.getId());
        }
    });
    return ContentValidityResult.create().notValidContentIds(invalidContentIds.build()).notReadyContentIds(notReadyContentIds.build()).build();
}
Also used : ContentQuery(com.enonic.xp.content.ContentQuery) IdFilter(com.enonic.xp.query.filter.IdFilter) ExistsFilter(com.enonic.xp.query.filter.ExistsFilter) ValueFilter(com.enonic.xp.query.filter.ValueFilter) BooleanFilter(com.enonic.xp.query.filter.BooleanFilter) Filter(com.enonic.xp.query.filter.Filter) FindContentByQueryResult(com.enonic.xp.content.FindContentByQueryResult) ContentIds(com.enonic.xp.content.ContentIds)

Example 10 with FindContentByQueryResult

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

the class ContentServiceImplTest_selectorSearch method same_site_first.

// Implement path search match first
@Disabled
@Test
public void same_site_first() throws Exception {
    final Content site1 = createContent(ContentPath.ROOT, "site1");
    final Content site2 = createContent(ContentPath.ROOT, "site2");
    final Content third = createContent(site1.getPath(), "Fisk ost");
    final Content second = createContent(site2.getPath(), "Fisk ost");
    final FunctionExpr fulltext = FunctionExpr.from("fulltext", ValueExpr.string("displayName"), ValueExpr.string("ost"));
    final OrderExpr order = FieldOrderExpr.create(IndexPath.from("_score"), OrderExpr.Direction.DESC);
    final ContentQuery query = ContentQuery.create().queryExpr(QueryExpr.from(new DynamicConstraintExpr(fulltext), order)).build();
    final FindContentByQueryResult result = contentService.find(FindContentByQueryParams.create().contentQuery(query).build());
    assertOrder(result, second, third);
}
Also used : FunctionExpr(com.enonic.xp.query.expr.FunctionExpr) ContentQuery(com.enonic.xp.content.ContentQuery) DynamicConstraintExpr(com.enonic.xp.query.expr.DynamicConstraintExpr) Content(com.enonic.xp.content.Content) FindContentByQueryResult(com.enonic.xp.content.FindContentByQueryResult) OrderExpr(com.enonic.xp.query.expr.OrderExpr) FieldOrderExpr(com.enonic.xp.query.expr.FieldOrderExpr) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Aggregations

FindContentByQueryResult (com.enonic.xp.content.FindContentByQueryResult)11 Test (org.junit.jupiter.api.Test)9 ContentQuery (com.enonic.xp.content.ContentQuery)4 Content (com.enonic.xp.content.Content)3 DynamicConstraintExpr (com.enonic.xp.query.expr.DynamicConstraintExpr)2 FieldOrderExpr (com.enonic.xp.query.expr.FieldOrderExpr)2 FunctionExpr (com.enonic.xp.query.expr.FunctionExpr)2 OrderExpr (com.enonic.xp.query.expr.OrderExpr)2 ContentId (com.enonic.xp.content.ContentId)1 ContentIds (com.enonic.xp.content.ContentIds)1 Contents (com.enonic.xp.content.Contents)1 FindContentByQueryParams (com.enonic.xp.content.FindContentByQueryParams)1 PropertySet (com.enonic.xp.data.PropertySet)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 HighlightedProperties (com.enonic.xp.highlight.HighlightedProperties)1 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)1 NodeHit (com.enonic.xp.node.NodeHit)1 NodeIds (com.enonic.xp.node.NodeIds)1 NodeQuery (com.enonic.xp.node.NodeQuery)1 Nodes (com.enonic.xp.node.Nodes)1