Hello,
I've tried (and succeeded) to reproduce your problem. Before getting
to the problem, first a small thing: Instead of using
HippoRepository repository = HippoRepositoryFactory.getHippoRepository();
Session previewSession = repository.login("previewuser",
"previewuserpass".toCharArray());
you can better use
final Repository repository =
HstServices.getComponentManager().getComponent(Repository.class.getName());
final SimpleCredentials previewCreds =
HstServices.getComponentManager().getComponent("javax.jcr.Credentials.preview");
final Session previewSession = repository.login(previewCreds);
This way, you get a preview session from a pool managed by the HST.
So I tried the following code:
try {
final Repository repository =
HstServices.getComponentManager().getComponent(Repository.class.getName());
final SimpleCredentials previewCreds =
HstServices.getComponentManager().getComponent("javax.jcr.Credentials.preview");
final Session previewSession = repository.login(previewCreds);
final Node previewScope =
previewSession.getRootNode().getNode("content/documents/gettingstarted");
HstRequestContext requestContext = RequestContextProvider.get();
HstQuery hstQuery =
requestContext.getContentBeansTool().createQueryManager(previewSession).createQuery(previewScope,NewsDocument.class,true);
Filter mloFilter = hstQuery.createFilter();
hstQuery.setFilter(mloFilter);
HstQueryResult hstResult = hstQuery.execute();
final HippoBeanIterator hippoBeans = hstResult.getHippoBeans();
while(hippoBeans.hasNext()) {
final HippoBean hippoBean = hippoBeans.nextHippoBean();
System.out.println(hippoBean.getPath());
System.out.println(hippoBean.getNode().getSession().getUserID());
System.out.println(Arrays.toString(hippoBean.getValueProvider().getStrings("hippo:availability")));
}
} catch (RepositoryException e) {
e.printStackTrace();
} catch (QueryException e) {
e.printStackTrace();
}
What the result is, is that you do get search results from the preview
session (hippoBean.getNode().getSession().getUserID() returns
previewuser), however, the HstQueryImpl contains the following
if ( RequestContextProvider.get() != null ) {
if (RequestContextProvider.get().isPreview() ) {
query.append(" and
(@").append(HippoNodeType.HIPPO_AVAILABILITY).append("='preview'").append(")");
} else {
query.append(" and
(@").append(HippoNodeType.HIPPO_AVAILABILITY).append("='live'").append(")");
}
}
Since the request context is for live, the query gets included that
hippo availability must be live.
We could make an enhancement to be able to search for hippo
availability 'preview' by for example making it possible to set it
explicitly. From a session itself, we cannot know whether it is meant
for a preview or live session (I do not want to deduce that from the
user name containing 'preview' or something)
You can file an improvement issue for this if you like and contact
helpdesk to get in planned in. Apologies for the inconvenience
Regards Ard
On Tue, Jan 27, 2015 at 8:16 AM, Global Edge Software Ltd