Search in sources :

Example 26 with QueryException

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;
}
Also used : QueryException(org.xwiki.query.QueryException) Query(org.xwiki.query.Query) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 27 with QueryException

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();
    }
}
Also used : QueryException(org.xwiki.query.QueryException) ArrayList(java.util.ArrayList) BaseObject(com.xpn.xwiki.objects.BaseObject) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 28 with QueryException

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);
    }
}
Also used : QueryException(org.xwiki.query.QueryException) InitializationException(org.xwiki.component.phase.InitializationException)

Example 29 with QueryException

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;
}
Also used : SolrIndexerException(org.xwiki.search.solr.internal.api.SolrIndexerException) QueryException(org.xwiki.query.QueryException) EntityReference(org.xwiki.model.reference.EntityReference) ArrayList(java.util.ArrayList) QueryException(org.xwiki.query.QueryException) SolrIndexerException(org.xwiki.search.solr.internal.api.SolrIndexerException)

Example 30 with QueryException

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;
}
Also used : SolrIndexerException(org.xwiki.search.solr.internal.api.SolrIndexerException) QueryException(org.xwiki.query.QueryException) EntityReference(org.xwiki.model.reference.EntityReference) ArrayList(java.util.ArrayList) QueryException(org.xwiki.query.QueryException) SolrIndexerException(org.xwiki.search.solr.internal.api.SolrIndexerException)

Aggregations

QueryException (org.xwiki.query.QueryException)57 Query (org.xwiki.query.Query)32 DocumentReference (org.xwiki.model.reference.DocumentReference)19 XWikiException (com.xpn.xwiki.XWikiException)18 ArrayList (java.util.ArrayList)14 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)11 BaseObject (com.xpn.xwiki.objects.BaseObject)8 Test (org.junit.Test)8 QueryFilter (org.xwiki.query.QueryFilter)7 XWikiContext (com.xpn.xwiki.XWikiContext)6 HashMap (java.util.HashMap)6 XWikiRestException (org.xwiki.rest.XWikiRestException)6 Event (org.xwiki.eventstream.Event)5 WikiReference (org.xwiki.model.reference.WikiReference)5 Date (java.util.Date)4 List (java.util.List)4 IconException (org.xwiki.icon.IconException)4 QueryManager (org.xwiki.query.QueryManager)4 SecureQuery (org.xwiki.query.SecureQuery)4 XWiki (com.xpn.xwiki.XWiki)3