/** * Returns a HstQuery for incoming beans (incoming beans within scope {@code scope}). You can add filters and ordering to the query before executing it * You need to add a <code>linkPath</code>: this is that path, that the incoming beans use to link to the HippoDocumentBean {@code bean}. For example, with 'myproject:link/@hippo:docbase' or even 'wildcard/@hippo:docbase' or * 'wildcard/wildcard/@hippo:docbase' where wildcard = * * * @param bean The HippoDocumentBean that you have, and for which you want to find the other beans that have a link to it (incoming beans) * @param scope the scope (hierarchical location) to search below for 'incoming beans' * @param linkPath the path where the 'incoming beans' have there link (mirror) stored, for example at myns:links/@hippo:docbase * @param beanMappingClass the type the 'incoming beans' should be of * @param includeSubTypes <code>true</code> when subtypes of beanMappingClass should be included in the result * @return a HstQuery that contains the constraints for 'incoming beans' to your <code>bean</code> * @throws QueryException when there is no HstRequestContext available, or another unexpected exception occurs */ public static HstQuery createIncomingBeansQuery(final HippoDocumentBean bean, final HippoBean scope, final String linkPath, final Class<? extends HippoBean> beanMappingClass, final boolean includeSubTypes) throws QueryException { final List<String> linkPaths = new ArrayList<>(); linkPaths.add(linkPath); return createIncomingBeansQuery(bean, scope, linkPaths, beanMappingClass, includeSubTypes); }
/** * Same as {@link #getFacetNavigationBean(String)} only now instead of a {@link String} query we * pass in a {@link HstQuery} * @see {@link #getFacetNavigationBean(String)} * */ public static HippoFacetNavigationBean getFacetNavigationBean(HstQuery query) throws HstComponentException { if(query == null) { return getFacetNavigationBean((String)null); } try { String queryAsString = "xpath("+query.getQueryAsString(true)+")"; return getFacetNavigationBean(queryAsString); } catch (QueryException e) { throw new HstComponentException("Unable to create a string representation of query", e); } }
/** * Tries to return a bean that is located in a faceted navigation tree below a result set. When it cannot be found, * or the bean is not of type <code>beanMappingClass</code>, <code>null</code> will be returned. * * @param <T> * @param query the free text search as {@link HstQuery} that is used for this faceted navigation * @param absBasePath the absolute path (starting with /) from where to get the faceted navigation bean for <code>relPath</code> and * <code>query</code>. The <code>absBasePath</code> is NOT allowed to point to or to a descendant of a faceted navigation * node * @param relPath the relative path from <code>absBasePath</code> to the faceted navigation node, which must not start with a / and is relative to the site content base path * @param beanMappingClass the class T must be of * @return The faceted navigation result document of type T and <code>null</code> if it cannot be found or is not of type <code>T</code> */ public static <T extends HippoBean> T getFacetedNavigationResultDocument(HstQuery query, String absBasePath, String relPath, Class<T> beanMappingClass) { if(query == null) { return getFacetedNavigationResultDocument((String)null, absBasePath, relPath, beanMappingClass); } try { String queryAsString = "xpath("+query.getQueryAsString(true)+")"; return getFacetedNavigationResultDocument(queryAsString, absBasePath, relPath, beanMappingClass); } catch (QueryException e) { throw new HstComponentException("Unable to create a string representation of query", e); } }
return getPreviewCmsQuerySession(requestContext, sessionIdentifier); userID = ((SimpleCredentials) cred).getUserID() + getCredentialsDomainSeparator() + "lazy";
Session querySession = getDisposableSession(requestContext, query); ObjectBeanManager objectBeanMngr = requestContext.getObjectBeanManager(querySession);
Session querySession = getDisposableSession(requestContext, query); ObjectBeanManager objectBeanMngr = requestContext.getObjectBeanManager(querySession);
/** * Same as {@link #getFacetNavigationBean(HstQuery)} only now instead of having the faceted navigation * node from the {@link ResolvedSiteMapItem} we add a <code>relPath</code> where it should be found * @see {@link #getFacetNavigationBean(String)} * @param query a {@link HstQuery} object * @param relPath the relative path from site base content to the faceted navigation node, which must not start with a / and is relative to the site content base path * @return the <code>HippoFacetNavigationBean</code> accounted for this <code>query</code> and <code>relPath</code> and <code>null</code> if we could not find the HippoFacetNavigationBean when the <code>query</code> is applied * @throws HstComponentException */ public static HippoFacetNavigationBean getFacetNavigationBean(HstQuery query, String relPath) throws HstComponentException { if(query == null) { return getFacetNavigationBean((String)null); } try { String queryAsString = "xpath("+query.getQueryAsString(true)+")"; return getFacetNavigationBean(relPath, queryAsString); } catch (QueryException e) { throw new HstComponentException("Unable to create a string representation of query", e); } }
/** * Returns a HstQuery for incoming beans (incoming beans within scope {@code scope}). * You can add filters and ordering to the query before executing it. * You need to add a <code>linkPath</code>: this is the path where the link to the HippoDocumentBean {@code bean} * can be found on the 'incoming bean'. * For example, with 'myproject:link/@hippo:docbase' or even 'wildcard/@hippo:docbase' or * 'wildcard/wildcard/@hippo:docbase' where wildcard = * * * @param bean The HippoDocumentBean that you have and for which you want to find the other beans that have a link to it (incoming beans) * @param scope the scope (hierarchical location) to search below for 'incoming beans' * @param linkPath the path where the 'incoming beans' have there link (mirror) stored, for example at myns:links/@hippo:docbase * @param beanMappingClass the type the 'incoming beans' should have * @return a HstQuery that contains the constraints for 'incoming beans' to your <code>bean</code> * @throws QueryException when there is no HstRequestContext available, or another unexpected exception occurs */ public static HstQuery createIncomingBeansQuery(final HippoDocumentBean bean, final HippoBean scope, final String linkPath, final Class<? extends HippoBean> beanMappingClass) throws QueryException { final List<String> linkPaths = new ArrayList<>(); linkPaths.add(linkPath); return createIncomingBeansQuery(bean, scope, linkPaths, beanMappingClass, false); }
/** * Tries to return a bean that is located in a faceted navigation tree below a result set. When it cannot be found, * or the bean is not of type <code>beanMappingClass</code>, <code>null</code> will be returned. * * @param <T> * @param query the free text search as {@link HstQuery} that is used for this faceted navigation * @param beanMappingClass the class T must be of * @return The faceted navigation result document of type T and <code>null</code> if it cannot be found or is not of type <code>T</code> */ public static <T extends HippoBean> T getFacetedNavigationResultDocument(HstQuery query, Class<T> beanMappingClass) { if(query == null) { return getFacetedNavigationResultDocument((String)null, beanMappingClass); } try { String queryAsString = "xpath("+query.getQueryAsString(true)+")"; return getFacetedNavigationResultDocument(queryAsString, beanMappingClass); } catch (QueryException e) { throw new HstComponentException("Unable to create a string representation of query", e); } }
/** * Same as {@link #getFacetNavigationBean(HstQuery)} only now instead of having the faceted navigation * node from the {@link ResolvedSiteMapItem} we add <code>absBasePath</code> and <code>relPath</code> where it should be found * @see {@link #getFacetNavigationBean(String)} * @param query a {@link HstQuery} object * @param absBasePath the absolute path (starting with /) from where to get the faceted navigation bean for <code>relPath</code> and * <code>query</code>. The <code>absBasePath</code> is NOT allowed to point to or to a descendant of a faceted navigation * node * @param relPath the relative path from absBasePath to the faceted navigation node, which must not start with a / and is relative to the site content base path * @return the <code>HippoFacetNavigationBean</code> accounted for this <code>query</code> and <code>relPath</code> and <code>null</code> if we could not find the HippoFacetNavigationBean when the <code>query</code> is applied * @throws HstComponentException */ public static HippoFacetNavigationBean getFacetNavigationBean(HstQuery query, String absBasePath, String relPath) throws HstComponentException { if(query == null) { return getFacetNavigationBean((String)null); } try { String queryAsString = "xpath("+query.getQueryAsString(true)+")"; return getFacetNavigationBean(absBasePath, relPath, queryAsString); } catch (QueryException e) { throw new HstComponentException("Unable to create a string representation of query", e); } }
/** * Returns a HstQuery for incoming beans (incoming beans within scope {@code scope}). You can add filters and ordering to the query before executing it * You need to add a <code>depth</code>: this is the maximum depth, that the incoming beans use to link to the HippoDocumentBean {@code bean}. For example, with 'myproject:link/@hippo:docbase' is depth 1, * 'myproject:somecompound/myproject:link/@hippo:docbase' is depth 2 * * @param bean The HippoDocumentBean that you have, and for which you want to find the other beans that have a link to it (incoming beans) * @param scope the scope (hierarchical location) to search below for 'incoming beans' * @param depth the <code>depth</code> until which the links below the HippoDocuments you want to find can be. Maximum depth is 4, when larger, a QueryException is thrown * @param beanMappingClass the type the 'incoming beans' should be of * @param includeSubTypes <code>true</code> when subtypes of beanMappingClass should be included in the result * @return a HstQuery that contains the constraints for 'incoming beans' to your <code>bean</code> * @throws QueryException when <code>depth</code> is larger than 4 */ public static HstQuery createIncomingBeansQuery(final HippoDocumentBean bean, final HippoBean scope, final int depth, Class<? extends HippoBean> beanMappingClass, final boolean includeSubTypes) throws QueryException { if (depth < 0 || depth > 4) { throw new FilterException("Depth must be between 0 and 4 (inclusive)"); } String path = "@hippo:docbase"; final List<String> linkPaths = new ArrayList<>(); linkPaths.add(path); for (int i = 1; i <= depth; i++) { path = "*/" + path; linkPaths.add(path); } return createIncomingBeansQuery(bean, scope, linkPaths, beanMappingClass, includeSubTypes); }
/** * Tries to return a bean that is located in a faceted navigation tree below a result set. When it cannot be found, * or the bean is not of type <code>beanMappingClass</code>, <code>null</code> will be returned. * * @param <T> * @param query the free text search as {@link HstQuery} that is used for this faceted navigation * @param relPath the relative path from site base content to the faceted navigation node, which must not start with a / and is relative to the site content base path * @param beanMappingClass the class T must be of * @return The faceted navigation result document of type T and <code>null</code> if it cannot be found or is not of type <code>T</code> */ public static <T extends HippoBean> T getFacetedNavigationResultDocument(HstQuery query, String relPath, Class<T> beanMappingClass) { if(query == null) { return getFacetedNavigationResultDocument((String)null, relPath, beanMappingClass); } try { String queryAsString = "xpath("+query.getQueryAsString(true)+")"; return getFacetedNavigationResultDocument(queryAsString, relPath, beanMappingClass); } catch (QueryException e) { throw new HstComponentException("Unable to create a string representation of query", e); } }
protected HippoFacetNavigationBean getFacetNavigationBean(final HstRequestContext context, String path, String query) { if (Strings.isNullOrEmpty(path)) { log.warn("Facetpath was empty {}", path); return null; } ResolvedSiteMapItem resolvedSiteMapItem = context.getResolvedSiteMapItem(); String resolvedContentPath = PathUtils.normalizePath(resolvedSiteMapItem.getRelativeContentPath()); String parsedQuery = cleanupSearchQuery(query); HippoFacetNavigationBean facNavBean; if (!StringUtils.isBlank(resolvedContentPath) && !resolvedContentPath.startsWith("/") && context.getSiteContentBaseBean().getBean(resolvedContentPath, HippoFacetNavigationBean.class) != null) { facNavBean = ContentBeanUtils.getFacetNavigationBean(resolvedContentPath, parsedQuery); } else { facNavBean = ContentBeanUtils.getFacetNavigationBean(path, parsedQuery); } return facNavBean; } }
/** * Returns a HstQuery for incoming beans (incoming beans within scope {@code scope}). * You can add filters and ordering to the query before executing it. * You need to add a <code>depth</code>: this is the maximum depth that the incoming beans use to link to the * HippoDocumentBean {@code bean}. For example, with 'myproject:link/@hippo:docbase' is depth 1, * 'myproject:somecompound/myproject:link/@hippo:docbase' is depth 2. * The link is assumed to be at path @hippo:docbase. * @param bean The HippoDocumentBean that you have and for which you want to find the other beans that have a link to it (incoming beans) * @param scope the scope (hierarchical location) to search below for 'incoming beans' * @param depth the <code>depth</code> until which the links below the HippoDocuments you want to find can be. Maximum depth is 4, when larger, a QueryException is thrown * @param beanMappingClass the specific type the 'incoming beans' should have * @return a HstQuery that contains the constraints for 'incoming beans' to your <code>bean</code> * @throws QueryException when <code>depth</code> is larger than 4 */ public static HstQuery createIncomingBeansQuery(final HippoDocumentBean bean, final HippoBean scope, final int depth, final Class<? extends HippoBean> beanMappingClass) throws QueryException { if (depth < 0 || depth > 4) { throw new FilterException("Depth must be between 0 and 4 (inclusive)"); } String path = "@hippo:docbase"; List<String> linkPaths = new ArrayList<>(); linkPaths.add(path); for (int i = 1; i <= depth; i++) { path = "*/" + path; linkPaths.add(path); } return createIncomingBeansQuery(bean, scope, linkPaths, beanMappingClass, false); }
/** * Tries to return a bean that is located in a faceted navigation tree below a result set. When it cannot be found, * or the bean is not of type <code>beanMappingClass</code>, <code>null</code> will be returned. * * @param <T> * @param query the free text search as String that is used for this faceted navigation. The query should already * have been processed by {@link org.hippoecm.hst.util.SearchInputParsingUtils#parse(String, boolean)} * if necessary. * @param relPath the relative path from site base content to the faceted navigation node, which must not start with a / and is relative to the site content base path * @param beanMappingClass the class T must be of * @return The faceted navigation result document of type T and <code>null</code> if it cannot be found or is not of type <code>T</code> */ public static <T extends HippoBean> T getFacetedNavigationResultDocument(final String query, final String relPath, final Class<T> beanMappingClass) { final HstRequestContext requestContext = RequestContextProvider.get(); if (requestContext == null) { throw new HstComponentException("Cannot call #getFacetNavigationBean without HstRequestContext"); } return getFacetedNavigationResultDocument(query, "/"+requestContext.getSiteContentBasePath(), relPath, beanMappingClass); }
/** * @see {@link #getFacetNavigationBean(String, String, String)} with <code>absBasePath</code> as "/"+ requestContext.getSiteContentBasePath(); */ public static HippoFacetNavigationBean getFacetNavigationBean(String relPath, String query) throws HstComponentException { final HstRequestContext requestContext = RequestContextProvider.get(); if (requestContext == null) { throw new HstComponentException("Cannot call #getFacetNavigationBean without HstRequestContext"); } if(relPath == null) { log.warn("Cannot return a content bean for relative path null for resolvedSitemapItem belonging to '{}'. Return null", requestContext.getResolvedSiteMapItem().getHstSiteMapItem().getId()); return null; } String absBasePath = "/"+ requestContext.getSiteContentBasePath(); return getFacetNavigationBean(absBasePath, relPath, query); }
try { for (AuthorEntry author : authors) { final HstQuery hstQuery = ContentBeanUtils.createIncomingBeansQuery(author, scopeBean, getSearchDepth(), clazz, true); hstQuery.setLimit(limit); hstQuery.addOrderByDescending(sortField);
/** * Tries to return a bean that is located in a faceted navigation tree below a result set. When it cannot be found, * or the bean is not of type <code>beanMappingClass</code>, <code>null</code> will be returned. * * @param <T> * @param query the free text search as String that is used for this faceted navigation * @param beanMappingClass the class T must be of * @return The faceted navigation result document of type T and <code>null</code> if it cannot be found or is not of type <code>T</code> */ public static <T extends HippoBean> T getFacetedNavigationResultDocument(String query, Class<T> beanMappingClass) { final HstRequestContext requestContext = RequestContextProvider.get(); if (requestContext == null) { throw new HstComponentException("Cannot call #getFacetNavigationBean without HstRequestContext"); } ResolvedSiteMapItem resolvedSiteMapItem = requestContext.getResolvedSiteMapItem(); String relPath = PathUtils.normalizePath(resolvedSiteMapItem.getRelativeContentPath()); return getFacetedNavigationResultDocument(query, relPath, beanMappingClass); }
/** * @see {@link #getFacetNavigationBean(String, String, String)} with <code>absBasePath</code> as "/"+ requestContext.getSiteContentBasePath() and * <code>relPath </code> as requestContext.getResolvedSiteMapItem().getRelativeContentPath() */ public static HippoFacetNavigationBean getFacetNavigationBean(String query) throws HstComponentException { final HstRequestContext requestContext = RequestContextProvider.get(); if (requestContext == null) { throw new HstComponentException("Cannot call #getFacetNavigationBean without HstRequestContext"); } ResolvedSiteMapItem resolvedSiteMapItem = requestContext.getResolvedSiteMapItem(); String relPath = PathUtils.normalizePath(resolvedSiteMapItem.getRelativeContentPath()); return getFacetNavigationBean(relPath, query); }
/** * Execute the search given a facet navigation scope. * * @param request current HST request * @param paramInfo component parameters * @param scope bean representing search scope * @param <T> type of component info interface * @return pageable search results, or null if search failed. */ protected <T extends EssentialsListComponentInfo> Pageable<HippoBean> doFacetedSearch(final HstRequest request, final T paramInfo, final HippoBean scope) { Pageable<HippoBean> pageable = DefaultPagination.emptyCollection(); final String relPath = SiteUtils.relativePathFrom(scope, request.getRequestContext()); final HippoFacetNavigationBean facetBean = ContentBeanUtils.getFacetNavigationBean(relPath, getSearchQuery(request)); if (facetBean != null) { final HippoResultSetBean resultSet = facetBean.getResultSet(); if (resultSet != null) { final HippoDocumentIterator<HippoBean> iterator = resultSet.getDocumentIterator(HippoBean.class); pageable = getPageableFactory().createPageable(iterator, resultSet.getCount().intValue(), paramInfo.getPageSize(), getCurrentPage(request)); } } return pageable; }