use of org.xwiki.query.QueryException in project xwiki-platform by xwiki.
the class RepositoryManager method resolveAuthorIdOnWiki.
private String resolveAuthorIdOnWiki(String wiki, String authorName, String[] authorElements, XWikiContext xcontext) {
Query query;
try {
query = this.queryManager.createQuery("from doc.object(XWiki.XWikiUsers) as user" + " where user.first_name like :userfirstname OR user.last_name like :userlastname", Query.XWQL);
query.bindValue("userfirstname", '%' + authorElements[0] + '%');
query.bindValue("userlastname", '%' + authorElements[authorElements.length - 1] + '%');
query.setWiki(wiki);
List<String> documentNames = query.execute();
if (!documentNames.isEmpty()) {
WikiReference wikiReference = new WikiReference(wiki);
for (String documentName : documentNames) {
DocumentReference documentReference = this.currentStringResolver.resolve(documentName, wikiReference);
String userDisplayName = xcontext.getWiki().getPlainUserName(documentReference, xcontext);
if (userDisplayName.equals(authorName)) {
return documentName;
}
}
}
} catch (QueryException e) {
this.logger.error("Failed to resolve extension author [{}]", authorName, e);
}
return null;
}
use of org.xwiki.query.QueryException in project xwiki-platform by xwiki.
the class DefaultIconSetManagerTest method getIconSetNamesWhenException.
@Test
public void getIconSetNamesWhenException() throws Exception {
// Mocks
QueryException exception = new QueryException("exception in the query", null, null);
when(queryManager.createQuery(any(), eq(Query.XWQL))).thenThrow(exception);
// Test
IconException caughtException = null;
try {
mocker.getComponentUnderTest().getIconSetNames();
} catch (IconException e) {
caughtException = e;
}
// Verify
assertNotNull(caughtException);
assertEquals("Failed to get the name of all icon sets.", caughtException.getMessage());
assertEquals(exception, caughtException.getCause());
}
use of org.xwiki.query.QueryException in project xwiki-platform by xwiki.
the class ScopeNotificationFilterClassMigrator method hibernateMigrate.
@Override
protected void hibernateMigrate() throws DataMigrationException, XWikiException {
XWikiContext context = contextProvider.get();
XWiki xwiki = context.getWiki();
try {
// Get every document having at least one NotificationPreferenceScopeClass XObject attached
Query query = queryManager.createQuery("select distinct doc.fullName from Document doc, " + "doc.object(XWiki.Notifications.Code.NotificationPreferenceScopeClass) as obj", Query.XWQL);
// Migrate each document to use the new XObject
for (String result : query.<String>execute()) {
DocumentReference userReference = resolver.resolve(result);
XWikiDocument userDocument = xwiki.getDocument(userReference, context);
logger.debug("Migrating document [{}]...", result);
try {
migrateDocument(userDocument);
} catch (XWikiException e) {
logger.warn("Failed to migrate document [{}].", result, e);
}
}
// When every documents have been migrated, we used to delete the old XClass,
// but it is not a good idea to delete a document in a migrator, when stores are not ready (such as
// recycle bin) and when other modules are not ready (like the SOLR server).
// See: https://jira.xwiki.org/browse/XWIKI-14749
// So we don't do anything.
} catch (QueryException e) {
logger.error("Failed to perform a query on the current wiki.", e);
}
}
use of org.xwiki.query.QueryException in project xwiki-platform by xwiki.
the class DefaultInstanceModel method getSpaceReferences.
@Override
public EntityReferenceTreeNode getSpaceReferences(WikiReference wikiReference) throws FilterException {
// Get the spaces
List<String> spaceReferenceStrings;
try {
spaceReferenceStrings = this.queryManager.getNamedQuery("getSpaces").setWiki(wikiReference.getName()).execute();
} catch (QueryException e) {
throw new FilterException(String.format("Failed to get the list of spaces in wiki [%s]", wikiReference), e);
}
// Get references
List<SpaceReference> spaceReferences = new ArrayList<>(spaceReferenceStrings.size());
for (String spaceReferenceString : spaceReferenceStrings) {
spaceReferences.add(this.spaceResolver.resolve(spaceReferenceString, wikiReference));
}
// Create the tree
EntityReferenceTree tree = new EntityReferenceTree(spaceReferences);
return tree.getChildren().iterator().next();
}
use of org.xwiki.query.QueryException in project xwiki-platform by xwiki.
the class XWikiGroupServiceImpl method getAllMatchedMembersNamesForGroup.
@Override
public Collection<String> getAllMatchedMembersNamesForGroup(String group, String matchField, int nb, int start, Boolean orderAsc, XWikiContext context) throws XWikiException {
// TODO: add cache mechanism.
XWikiDocument groupDocument = new XWikiDocument(this.currentMixedDocumentReferenceResolver.resolve(group));
Map<String, Object> parameterValues = new HashMap<String, Object>();
// //////////////////////////////////////
// Create the query string
StringBuilder queryString = new StringBuilder("SELECT field.value");
queryString.append(' ').append(createMatchGroupMembersWhereClause(groupDocument.getFullName(), matchField, orderAsc, parameterValues));
try {
// //////////////////////////////////////
// Create the query
QueryManager qm = context.getWiki().getStore().getQueryManager();
Query query = qm.createQuery(queryString.toString(), Query.HQL);
for (Map.Entry<String, Object> entry : parameterValues.entrySet()) {
query.bindValue(entry.getKey(), entry.getValue());
}
query.setOffset(start);
query.setLimit(nb);
query.setWiki(groupDocument.getDocumentReference().getWikiReference().getName());
return query.execute();
} catch (QueryException ex) {
throw new XWikiException(0, 0, ex.getMessage(), ex);
}
}
Aggregations