use of org.xwiki.query.QueryException in project xwiki-platform by xwiki.
the class UsedValuesListQueryBuilder method canView.
private boolean canView(ListClass listClass, String value, long count) {
// We can't check all the documents where this value occurs so we check just one of them, chosen randomly.
long offset = ThreadLocalRandom.current().nextLong(count);
String statement = String.format("select obj.name from BaseObject as obj, %2$s " + "where obj.className = :className and obj.name <> :templateName " + "and prop.id.id = obj.id and prop.id.name = :propertyName and %1$s = :propertyValue", getSelectColumnAndFromTable(listClass));
try {
Query query = this.queryManager.createQuery(statement, Query.HQL);
bindParameterValues(query, listClass);
query.bindValue("propertyValue", value);
query.setWiki(listClass.getReference().extractReference(EntityType.WIKI).getName());
query.setOffset((int) offset).setLimit(1);
List<?> results = query.execute();
if (results.size() > 0) {
DocumentReference documentReference = this.documentReferenceResolver.resolve((String) results.get(0));
if (this.authorization.hasAccess(Right.VIEW, documentReference)) {
return true;
}
}
} catch (QueryException e) {
this.logger.warn("Failed to check if the list value is viewable. Root cause is [{}]." + " Continue assuming the value is not viewable.", ExceptionUtils.getRootCauseMessage(e));
}
return false;
}
use of org.xwiki.query.QueryException in project xwiki-platform by xwiki.
the class AbstractSheetBinder method getDocuments.
@Override
public List<DocumentReference> getDocuments(DocumentReference expectedSheetRef) {
this.sheetBindingsQuery.setWiki(expectedSheetRef.getWikiReference().getName());
try {
List<Object[]> sheetBindings = this.sheetBindingsQuery.execute();
List<DocumentReference> documentReferences = new ArrayList<DocumentReference>();
for (Object[] sheetBinding : sheetBindings) {
DocumentReference docRef = this.documentReferenceResolver.resolve((String) sheetBinding[0], expectedSheetRef);
DocumentReference sheetRef = this.documentReferenceResolver.resolve((String) sheetBinding[1], docRef);
if (sheetRef.equals(expectedSheetRef)) {
documentReferences.add(docRef);
}
}
return documentReferences;
} catch (QueryException e) {
this.logger.warn("Failed to query sheet bindings.", e);
return Collections.emptyList();
}
}
use of org.xwiki.query.QueryException in project xwiki-platform by xwiki.
the class AbstractSheetBinder method initialize.
@Override
public void initialize() throws InitializationException {
try {
String statement = "select doc.fullName, prop.value from XWikiDocument doc, BaseObject obj, StringProperty prop where " + "obj.className=:sheetBindingClass and obj.name=doc.fullName and obj.id=prop.id.id and " + "prop.id.name=:sheetProperty order by doc.fullName";
this.sheetBindingsQuery = this.queryManager.createQuery(statement, Query.HQL);
this.sheetBindingsQuery.bindValue("sheetBindingClass", getSheetBindingClass());
this.sheetBindingsQuery.bindValue("sheetProperty", SHEET_PROPERTY);
} catch (QueryException e) {
throw new InitializationException("Failed to create query for retrieving the list of sheet bindings.", e);
}
}
use of org.xwiki.query.QueryException in project xwiki-platform by xwiki.
the class WikiSolrReferenceResolver method getReferences.
@Override
public List<EntityReference> getReferences(EntityReference wikiReference) throws SolrIndexerException {
List<EntityReference> result = new ArrayList<EntityReference>();
// Ignore the wiki reference because it is not indexable.
List<String> localSpaceRefs = null;
// Make sure the list of spaces is from the requested wiki.
try {
localSpaceRefs = this.queryManager.getNamedQuery("getSpaces").setWiki(wikiReference.getName()).execute();
} catch (QueryException e) {
throw new SolrIndexerException("Failed to query wiki [" + wikiReference.getName() + "] spaces", e);
}
// Visit each space
for (String localSpaceRef : localSpaceRefs) {
EntityReference spaceReference = this.explicitEntityReferenceResolver.resolve(localSpaceRef, EntityType.SPACE, wikiReference);
try {
Iterables.addAll(result, this.spaceResolverProvider.get().getReferences(spaceReference));
} catch (Exception e) {
this.logger.error("Failed to resolve references for space [" + spaceReference + "]", e);
}
}
return result;
}
use of org.xwiki.query.QueryException in project xwiki-platform by xwiki.
the class SpaceSolrReferenceResolver method getReferences.
@Override
public List<EntityReference> getReferences(EntityReference spaceReference) throws SolrIndexerException {
List<EntityReference> result = new ArrayList<EntityReference>();
EntityReference wikiReference = spaceReference.extractReference(EntityType.WIKI);
String localSpaceReference = this.localEntityReferenceSerializer.serialize(spaceReference);
// Ignore the space reference because it is not indexable.
// Make sure the list of spaces is from the requested wiki
List<String> documentNames;
try {
documentNames = this.queryManager.getNamedQuery("getSpaceDocsName").setWiki(wikiReference.getName()).bindValue("space", localSpaceReference).execute();
} catch (QueryException e) {
throw new SolrIndexerException("Failed to query space [" + spaceReference + "] documents", e);
}
for (String documentName : documentNames) {
EntityReference documentReference = new EntityReference(documentName, EntityType.DOCUMENT, spaceReference);
try {
Iterables.addAll(result, this.documentResolverProvider.get().getReferences(documentReference));
} catch (Exception e) {
this.logger.error("Failed to resolve references for document [" + documentReference + "]", e);
}
}
return result;
}
Aggregations