use of org.xwiki.query.QueryException in project xwiki-platform by xwiki.
the class DefaultWikiCopier method copyDocuments.
@Override
public void copyDocuments(String fromWikiId, String toWikiId, boolean withHistory) throws WikiManagerException {
XWikiContext context = xcontextProvider.get();
XWiki xwiki = context.getWiki();
this.progress.pushLevelProgress(2, this);
try {
// Get documents
this.progress.startStep(this, "Get documents to copy");
Query query = queryManager.createQuery("select distinct doc.fullName from Document as doc", Query.XWQL);
query.setWiki(fromWikiId);
List<String> documentFullnames = query.execute();
this.progress.endStep(this);
// Copy documents
this.progress.startStep(this, "Copy documents");
this.progress.pushLevelProgress(documentFullnames.size(), this);
WikiReference fromWikiReference = new WikiReference(fromWikiId);
try {
for (String documentFullName : documentFullnames) {
this.progress.startStep(this);
DocumentReference origDocReference = documentReferenceResolver.resolve(documentFullName, fromWikiReference);
DocumentReference newDocReference = origDocReference.setWikiReference(new WikiReference(toWikiId));
logger.info("Copying document [{}] to [{}].", origDocReference, newDocReference);
xwiki.copyDocument(origDocReference, newDocReference, null, !withHistory, true, context);
logger.info("Done copying document [{}] to [{}].", origDocReference, newDocReference);
this.progress.endStep(this);
}
} finally {
this.progress.popLevelProgress(this);
this.progress.endStep(this);
}
} catch (QueryException e) {
WikiManagerException thrownException = new WikiManagerException("Unable to get the list of wiki documents to copy.", e);
logger.error(thrownException.getMessage(), thrownException);
throw thrownException;
} catch (XWikiException e) {
WikiManagerException thrownException = new WikiManagerException("Failed to copy documents.", e);
logger.error(thrownException.getMessage(), thrownException);
throw thrownException;
} finally {
this.progress.popLevelProgress(this);
}
}
use of org.xwiki.query.QueryException in project xwiki-platform by xwiki.
the class WikiDescriptorMigratorTest method hibernateMigrateWhenQueryException.
@Test
public void hibernateMigrateWhenQueryException() throws Exception {
List<String> documentList = new ArrayList<>();
documentList.add("XWiki.XWikiServerSubwiki1");
Exception exception = new QueryException("error in queryManager.createQuery()", null, null);
when(queryManager.createQuery(any(), eq(Query.HQL))).thenThrow(exception);
// Test
mocker.getComponentUnderTest().hibernateMigrate();
// Verify
verify(mocker.getMockedLogger()).error("Failed to perform a query on the main wiki.", exception);
}
use of org.xwiki.query.QueryException in project xwiki-platform by xwiki.
the class SolrQueryExecutor method execute.
@Override
public <T> List<T> execute(Query query) throws QueryException {
this.progress.startStep(query, "query.solr.progress.execute", "Execute Solr query [{}]", query);
this.progress.pushLevelProgress(3, query);
try {
this.progress.startStep(query, "query.solr.progress.execute.prepare", "Prepare");
SolrInstance solrInstance = solrInstanceProvider.get();
SolrQuery solrQuery = createSolrQuery(query);
this.progress.startStep(query, "query.solr.progress.execute.execute", "Execute");
QueryResponse response = solrInstance.query(solrQuery);
this.progress.startStep(query, "query.solr.progress.execute.filter", "Filter");
// Check access rights need to be checked before returning the response.
// FIXME: this is not really the best way, mostly because at this point all grouping operations
// have already been performed and any change on the result will not ensure that the grouping
// information (facets, highlighting, maxScore, etc.) is still relevant.
// A better way would be using a PostFilter as described in this article:
// http://java.dzone.com/articles/custom-security-filtering-solr
// Basically, we would be asking
List<DocumentReference> usersToCheck = new ArrayList<>(2);
if (query instanceof SecureQuery) {
if (((SecureQuery) query).isCurrentUserChecked()) {
usersToCheck.add(xcontextProvider.get().getUserReference());
}
if (((SecureQuery) query).isCurrentAuthorChecked()) {
usersToCheck.add(xcontextProvider.get().getAuthorReference());
}
} else {
usersToCheck.add(xcontextProvider.get().getUserReference());
usersToCheck.add(xcontextProvider.get().getAuthorReference());
}
if (!usersToCheck.isEmpty()) {
filterResponse(response, usersToCheck);
}
return (List<T>) Arrays.asList(response);
} catch (Exception e) {
throw new QueryException("Exception while executing query", query, e);
} finally {
this.progress.popLevelProgress(query);
this.progress.endStep(query);
}
}
use of org.xwiki.query.QueryException in project xwiki-platform by xwiki.
the class RecordableEventMigrator method hibernateMigrate.
@Override
protected void hibernateMigrate() throws DataMigrationException, XWikiException {
String hql = "select event from ActivityEventImpl event where event.page LIKE concat(event.wiki, ':%')";
try {
List<ActivityEventImpl> events;
do {
Query query = queryManager.createQuery(hql, Query.HQL);
query.setLimit(50);
events = query.execute();
for (ActivityEventImpl event : events) {
fixEvent(event);
}
} while (!events.isEmpty());
} catch (QueryException e) {
throw new DataMigrationException("Failed to fix RecordableEvent problems.", e);
}
}
use of org.xwiki.query.QueryException in project xwiki-platform by xwiki.
the class DefaultIconSetManager method getIconSet.
@Override
public IconSet getIconSet(String name) throws IconException {
// Special case: the default icon theme
if (DEFAULT_ICONSET_NAME.equals(name)) {
return getDefaultIconSet();
}
// Get the icon set from the cache
IconSet iconSet = iconSetCache.get(name, wikiDescriptorManager.getCurrentWikiId());
// Load it if it is not loaded yet
if (iconSet == null) {
try {
// Search by name
String xwql = "FROM doc.object(IconThemesCode.IconThemeClass) obj WHERE obj.name = :name";
Query query = queryManager.createQuery(xwql, Query.XWQL);
query.bindValue("name", name);
List<String> results = query.execute();
if (results.isEmpty()) {
return null;
}
// Get the first result
String docName = results.get(0);
DocumentReference docRef = documentReferenceResolver.resolve(docName);
// Load the icon theme
iconSet = iconSetLoader.loadIconSet(docRef);
// Put it in the cache
iconSetCache.put(docRef, iconSet);
iconSetCache.put(name, wikiDescriptorManager.getCurrentWikiId(), iconSet);
} catch (QueryException e) {
throw new IconException(String.format("Failed to load the icon set [%s].", name), e);
}
}
// Return the icon set
return iconSet;
}
Aggregations