Search in sources :

Example 1 with BranchPath

use of com.enonic.xp.repo.impl.cache.BranchPath in project xp by enonic.

the class BranchServiceImpl method doGetByPath.

private NodeBranchEntry doGetByPath(final NodePath nodePath, final InternalContext context) {
    final BranchDocumentId branchDocumentId = this.pathCache.get(new BranchPath(context.getRepositoryId(), context.getBranch(), nodePath));
    if (branchDocumentId != null) {
        return getFromCache(nodePath, context, branchDocumentId);
    }
    final NodeBranchQuery query = NodeBranchQuery.create().addQueryFilter(ValueFilter.create().fieldName(BranchIndexPath.PATH.getPath()).addValue(ValueFactory.newString(nodePath.toString())).build()).addQueryFilter(ValueFilter.create().fieldName(BranchIndexPath.BRANCH_NAME.getPath()).addValue(ValueFactory.newString(context.getBranch().getValue())).build()).size(1).build();
    final SearchResult result = this.searchDao.search(SearchRequest.create().searchSource(SingleRepoStorageSource.create(context.getRepositoryId(), SingleRepoStorageSource.Type.BRANCH)).returnFields(BRANCH_RETURN_FIELDS).query(query).searchPreference(context.getSearchPreference()).build());
    if (!result.isEmpty()) {
        final NodeBranchEntry nodeBranchEntry = NodeBranchVersionFactory.create(result.getHits().getFirst().getReturnValues());
        doCache(context, nodeBranchEntry.getNodePath(), nodeBranchEntry.getNodeId());
        return nodeBranchEntry;
    }
    return null;
}
Also used : BranchPath(com.enonic.xp.repo.impl.cache.BranchPath) NodeBranchQuery(com.enonic.xp.repo.impl.branch.search.NodeBranchQuery) SearchResult(com.enonic.xp.repo.impl.search.result.SearchResult) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry)

Aggregations

NodeBranchEntry (com.enonic.xp.node.NodeBranchEntry)1 NodeBranchQuery (com.enonic.xp.repo.impl.branch.search.NodeBranchQuery)1 BranchPath (com.enonic.xp.repo.impl.cache.BranchPath)1 SearchResult (com.enonic.xp.repo.impl.search.result.SearchResult)1