Search in sources :

Example 1 with ReturnValue

use of com.enonic.xp.repo.impl.ReturnValue in project xp by enonic.

the class NodeVersionQueryResultFactory method createVersionEntry.

private static NodeVersionMetadata createVersionEntry(final SearchHit hit) {
    final String timestamp = getStringValue(hit, VersionIndexPath.TIMESTAMP, true);
    final String versionId = getStringValue(hit, VersionIndexPath.VERSION_ID, true);
    final String nodeBlobKey = getStringValue(hit, VersionIndexPath.NODE_BLOB_KEY, true);
    final String indexConfigBlobKey = getStringValue(hit, VersionIndexPath.INDEX_CONFIG_BLOB_KEY, true);
    final String accessControlBlobKey = getStringValue(hit, VersionIndexPath.ACCESS_CONTROL_BLOB_KEY, true);
    final ReturnValue binaryBlobKeyReturnValue = hit.getField(VersionIndexPath.BINARY_BLOB_KEYS.getPath(), false);
    final String nodePath = getStringValue(hit, VersionIndexPath.NODE_PATH, true);
    final String nodeId = getStringValue(hit, VersionIndexPath.NODE_ID, true);
    final String commitId = getStringValue(hit, VersionIndexPath.COMMIT_ID, false);
    final NodeVersionKey nodeVersionKey = NodeVersionKey.from(nodeBlobKey, indexConfigBlobKey, accessControlBlobKey);
    final BlobKeys binaryBlobKeys = toBlobKeys(binaryBlobKeyReturnValue);
    return NodeVersionMetadata.create().nodeVersionId(NodeVersionId.from(versionId)).nodeVersionKey(nodeVersionKey).binaryBlobKeys(binaryBlobKeys).timestamp(isNullOrEmpty(timestamp) ? null : Instant.parse(timestamp)).nodePath(NodePath.create(nodePath).build()).nodeId(NodeId.from(nodeId)).nodeCommitId(isNullOrEmpty(commitId) ? null : NodeCommitId.from(commitId)).build();
}
Also used : BlobKeys(com.enonic.xp.blob.BlobKeys) NodeVersionKey(com.enonic.xp.blob.NodeVersionKey) ReturnValue(com.enonic.xp.repo.impl.ReturnValue)

Example 2 with ReturnValue

use of com.enonic.xp.repo.impl.ReturnValue in project xp by enonic.

the class FindNodesDependenciesCommand method addNodeIdsFromReferenceReturnValues.

private void addNodeIdsFromReferenceReturnValues(final SearchResult result, final NodeIds.Builder builder) {
    for (SearchHit hit : result.getHits()) {
        final ReturnValue returnValue = hit.getReturnValues().get(NodeIndexPath.REFERENCE.getPath());
        if (returnValue == null || returnValue.getValues().isEmpty()) {
            continue;
        }
        returnValue.getValues().stream().map((value) -> NodeId.from(value.toString())).filter((value) -> !processed.contains(value)).filter((value) -> !excludedIds.contains(value)).forEach(builder::add);
    }
}
Also used : IdFilter(com.enonic.xp.query.filter.IdFilter) ReturnFields(com.enonic.xp.repo.impl.ReturnFields) ReturnValue(com.enonic.xp.repo.impl.ReturnValue) NodeIndexPath(com.enonic.xp.node.NodeIndexPath) ExistsFilter(com.enonic.xp.query.filter.ExistsFilter) Set(java.util.Set) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) SingleRepoSearchSource(com.enonic.xp.repo.impl.SingleRepoSearchSource) NodeId(com.enonic.xp.node.NodeId) HashSet(java.util.HashSet) SearchResult(com.enonic.xp.repo.impl.search.result.SearchResult) ContextAccessor(com.enonic.xp.context.ContextAccessor) SearchHit(com.enonic.xp.repo.impl.search.result.SearchHit) NodeQuery(com.enonic.xp.node.NodeQuery) NodeIds(com.enonic.xp.node.NodeIds) SearchHit(com.enonic.xp.repo.impl.search.result.SearchHit) ReturnValue(com.enonic.xp.repo.impl.ReturnValue)

Example 3 with ReturnValue

use of com.enonic.xp.repo.impl.ReturnValue in project xp by enonic.

the class SearchHit method doGetField.

private ReturnValue doGetField(final String fieldName, final boolean failOnMissing) {
    final String normalizedFieldName = IndexFieldNameNormalizer.normalize(fieldName);
    final ReturnValue returnValue = returnValues.get(normalizedFieldName);
    if (failOnMissing && returnValue == null) {
        throw new RuntimeException("Expected field " + normalizedFieldName + " in result not found");
    }
    return returnValue;
}
Also used : ReturnValue(com.enonic.xp.repo.impl.ReturnValue)

Example 4 with ReturnValue

use of com.enonic.xp.repo.impl.ReturnValue in project xp by enonic.

the class NodeVersionFactory method create.

public static NodeVersionMetadata create(final GetResult getResult) {
    final ReturnValues values = getResult.getReturnValues();
    final String versionId = values.getSingleValue(VersionIndexPath.VERSION_ID.getPath()).toString();
    final String nodeBlobKey = values.getSingleValue(VersionIndexPath.NODE_BLOB_KEY.getPath()).toString();
    final String indexConfigBlobKey = values.getSingleValue(VersionIndexPath.INDEX_CONFIG_BLOB_KEY.getPath()).toString();
    final String accessControlBlobKey = values.getSingleValue(VersionIndexPath.ACCESS_CONTROL_BLOB_KEY.getPath()).toString();
    final ReturnValue binaryBlobKeysReturnValue = values.get(VersionIndexPath.BINARY_BLOB_KEYS.getPath());
    final Instant timestamp = Instant.parse(values.getSingleValue(VersionIndexPath.TIMESTAMP.getPath()).toString());
    final String id = values.getSingleValue(VersionIndexPath.NODE_ID.getPath()).toString();
    final String path = values.getSingleValue(VersionIndexPath.NODE_PATH.getPath()).toString();
    final Object commitId = values.getSingleValue(VersionIndexPath.COMMIT_ID.getPath());
    final NodeVersionKey nodeVersionKey = NodeVersionKey.from(nodeBlobKey, indexConfigBlobKey, accessControlBlobKey);
    final BlobKeys binaryBlobKeys = toBlobKeys(binaryBlobKeysReturnValue);
    return NodeVersionMetadata.create().nodeId(NodeId.from(id)).nodePath(NodePath.create(path).build()).timestamp(timestamp).nodeVersionId(NodeVersionId.from(versionId)).nodeVersionKey(nodeVersionKey).binaryBlobKeys(binaryBlobKeys).nodeCommitId(commitId == null ? null : NodeCommitId.from(commitId.toString())).build();
}
Also used : BlobKeys(com.enonic.xp.blob.BlobKeys) NodeVersionKey(com.enonic.xp.blob.NodeVersionKey) Instant(java.time.Instant) ReturnValue(com.enonic.xp.repo.impl.ReturnValue) ReturnValues(com.enonic.xp.repo.impl.ReturnValues)

Example 5 with ReturnValue

use of com.enonic.xp.repo.impl.ReturnValue in project xp by enonic.

the class ReturnValueTest method addList.

@Test
public void addList() throws Exception {
    List<String> values = new ArrayList<>();
    values.add("a");
    values.add("b");
    values.add("c");
    final ReturnValue returnValue = ReturnValue.create(values);
    assertEquals(3, returnValue.getValues().size());
    assertEquals("a", returnValue.getSingleValue());
}
Also used : ArrayList(java.util.ArrayList) ReturnValue(com.enonic.xp.repo.impl.ReturnValue) Test(org.junit.jupiter.api.Test)

Aggregations

ReturnValue (com.enonic.xp.repo.impl.ReturnValue)5 BlobKeys (com.enonic.xp.blob.BlobKeys)2 NodeVersionKey (com.enonic.xp.blob.NodeVersionKey)2 ContextAccessor (com.enonic.xp.context.ContextAccessor)1 NodeId (com.enonic.xp.node.NodeId)1 NodeIds (com.enonic.xp.node.NodeIds)1 NodeIndexPath (com.enonic.xp.node.NodeIndexPath)1 NodeQuery (com.enonic.xp.node.NodeQuery)1 ExistsFilter (com.enonic.xp.query.filter.ExistsFilter)1 IdFilter (com.enonic.xp.query.filter.IdFilter)1 ReturnFields (com.enonic.xp.repo.impl.ReturnFields)1 ReturnValues (com.enonic.xp.repo.impl.ReturnValues)1 SingleRepoSearchSource (com.enonic.xp.repo.impl.SingleRepoSearchSource)1 SearchHit (com.enonic.xp.repo.impl.search.result.SearchHit)1 SearchResult (com.enonic.xp.repo.impl.search.result.SearchResult)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Function (java.util.function.Function)1