Search in sources :

Example 46 with ContentId

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

the class ContentIdConverterTest method testSameType.

@Test
public void testSameType() {
    final ContentId id = ContentId.from("/123");
    assertSame(id, Converters.convert(id, ContentId.class));
}
Also used : ContentId(com.enonic.xp.content.ContentId) Test(org.junit.jupiter.api.Test)

Example 47 with ContentId

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

the class IssueQueryNodeQueryTranslator method translate.

public static NodeQuery translate(final IssueQuery issueQuery) {
    final NodeQuery.Builder builder = NodeQuery.create();
    final ValueFilter issueCollectionFilter = ValueFilter.create().fieldName(NodeIndexPath.NODE_TYPE.getPath()).addValue(ValueFactory.newString(IssueConstants.ISSUE_NODE_COLLECTION.getName())).build();
    if (issueQuery.isCount()) {
        builder.searchMode(SearchMode.COUNT);
    }
    builder.from(issueQuery.getFrom()).size(issueQuery.getSize()).addQueryFilter(issueCollectionFilter);
    final PrincipalKey creator = issueQuery.getCreator();
    if (creator != null) {
        builder.addQueryFilter(ValueFilter.create().fieldName(CREATOR).addValues(creator.toString()).build());
    }
    final PrincipalKeys approvers = issueQuery.getApprovers();
    if (approvers != null && approvers.isNotEmpty()) {
        builder.addQueryFilter(ValueFilter.create().fieldName(APPROVERS).addValues(approvers.stream().map(PrincipalKey::toString).collect(toList())).build());
    }
    final ContentIds items = issueQuery.getItems();
    if (items != null && items.isNotEmpty()) {
        builder.addQueryFilter(ValueFilter.create().fieldName(PUBLISH_REQUEST_ITEM_ID).addValues(items.stream().map(ContentId::toString).collect(toList())).build());
    }
    final IssueStatus status = issueQuery.getStatus();
    if (status != null) {
        builder.addQueryFilter(ValueFilter.create().fieldName(STATUS).addValues(status.toString()).build());
    }
    final IssueType type = issueQuery.getType();
    if (type != null) {
        final Filter isOfType = ValueFilter.create().fieldName(TYPE).addValues(type.toString()).build();
        if (type == IssueType.STANDARD) {
            final Filter notExists = BooleanFilter.create().mustNot(ExistsFilter.create().fieldName(TYPE).build()).build();
            final Filter isStandard = BooleanFilter.create().should(isOfType).should(notExists).build();
            builder.addQueryFilter(isStandard);
        } else {
            builder.addQueryFilter(isOfType);
        }
    }
    builder.setOrderExpressions(IssueConstants.DEFAULT_CHILD_ORDER.getOrderExpressions());
    return builder.build();
}
Also used : PrincipalKeys(com.enonic.xp.security.PrincipalKeys) 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) IssueType(com.enonic.xp.issue.IssueType) NodeQuery(com.enonic.xp.node.NodeQuery) ContentIds(com.enonic.xp.content.ContentIds) ValueFilter(com.enonic.xp.query.filter.ValueFilter) ContentId(com.enonic.xp.content.ContentId) PrincipalKey(com.enonic.xp.security.PrincipalKey) IssueStatus(com.enonic.xp.issue.IssueStatus)

Example 48 with ContentId

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

the class ComponentHandlerWorker method getFragmentComponent.

private Component getFragmentComponent(final FragmentComponent component) {
    final ContentId contentId = component.getFragment();
    if (contentId == null) {
        return null;
    }
    try {
        final Content fragmentContent = contentService.getById(contentId);
        if (!fragmentContent.hasPage() || !fragmentContent.getType().isFragment()) {
            return null;
        }
        final Page page = fragmentContent.getPage();
        return page.getFragment();
    } catch (ContentNotFoundException e) {
        return null;
    }
}
Also used : ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) Content(com.enonic.xp.content.Content) ContentId(com.enonic.xp.content.ContentId) Page(com.enonic.xp.page.Page)

Example 49 with ContentId

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

the class ContentAuditLogSupportImpl method doDuplicate.

private void doDuplicate(final DuplicateContentParams params, final DuplicateContentsResult result, final Context rootContext) {
    if (params.getContentId() == null) {
        return;
    }
    final PropertyTree data = new PropertyTree();
    final PropertySet paramsSet = data.addSet("params");
    final PropertySet resultSet = data.addSet("result");
    paramsSet.addString("contentId", params.getContentId().toString());
    paramsSet.addBoolean("includeChildren", params.getIncludeChildren());
    if (params.getCreator() != null) {
        paramsSet.addString("creator", params.getCreator().getId());
    }
    resultSet.addStrings("duplicatedContents", result.getDuplicatedContents().stream().map(ContentId::toString).collect(Collectors.toSet()));
    log("system.content.duplicate", data, result.getDuplicatedContents(), rootContext);
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) ContentId(com.enonic.xp.content.ContentId)

Example 50 with ContentId

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

the class ContentAuditLogSupportImpl method doUnpublishContent.

private void doUnpublishContent(final UnpublishContentParams params, final UnpublishContentsResult result, final Context rootContext) {
    if (params.getContentIds() == null) {
        return;
    }
    final PropertyTree data = new PropertyTree();
    final PropertySet paramsSet = data.addSet("params");
    final PropertySet resultSet = data.addSet("result");
    paramsSet.addStrings("contentIds", params.getContentIds().stream().map(ContentId::toString).collect(Collectors.toList()));
    paramsSet.addBoolean("includeChildren", params.isIncludeChildren());
    if (params.getUnpublishBranch() != null) {
        paramsSet.addString("unpublishBranch", params.getUnpublishBranch().getValue());
    }
    addContents(resultSet, result.getUnpublishedContents(), "unpublishedContents");
    log("system.content.unpublishContent", data, result.getUnpublishedContents(), rootContext);
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) ContentId(com.enonic.xp.content.ContentId)

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