@Test public void hibernateMigrateWhenXWikiException() throws Exception { List<String> documentList = new ArrayList<>(); documentList.add("XWiki.XWikiServerSubwiki1"); Query query = mock(Query.class); when(queryManager.createQuery(any(), eq(Query.HQL))).thenReturn(query); when(query.<String>execute()).thenReturn(documentList); DocumentReference documentReference = new DocumentReference("mainWiki", "XWiki", "XWikiServerSubwiki1"); when(documentReferenceResolver.resolve(documentList.get(0))).thenReturn(documentReference); Exception exception = new XWikiException(0, 0, "error in xwiki.getDocument()"); when(xwiki.getDocument(documentReference, context)).thenThrow(exception); mocker.getComponentUnderTest().hibernateMigrate(); verify(mocker.getMockedLogger()).warn("Failed to get or save the wiki descriptor document [{}]. You" + " will not see the corresponding wiki in the Wiki Index unless you give it a Pretty Name manually. {}", documentList.get(0), ExceptionUtils.getRootCauseMessage(exception)); }
@Override protected void hibernateMigrate() throws DataMigrationException, XWikiException { String hql = "SELECT DISTINCT doc.fullName FROM XWikiDocument doc, BaseObject obj WHERE doc.fullName = obj.name" + " AND obj.className = :className AND doc.fullName <> :template AND doc.fullName NOT IN " + "(SELECT DISTINCT doc2.fullName FROM XWikiDocument doc2, BaseObject obj2, StringProperty propPrettyName" + " WHERE doc2.fullName = obj2.name AND obj2.className = :className" + " AND propPrettyName.id = obj2.id AND propPrettyName.name = :propertyName)"; try { Query query = queryManager.createQuery(hql, Query.HQL); query.bindValue("className", String.format("%s.%s", XWiki.SYSTEM_SPACE, XWikiServerClassDocumentInitializer.DOCUMENT_NAME)); query.bindValue("propertyName", XWikiServerClassDocumentInitializer.FIELD_WIKIPRETTYNAME); query.bindValue("template", "XWiki.XWikiServerClassTemplate"); List<String> results = query.execute(); for (String result : results) { fixDocument(result); } } catch (QueryException e) { logger.error("Failed to perform a query on the main wiki.", e); } }
WikiDescriptorMigrator extends AbstractHibernateDataMigration { @Override protected void hibernateMigrate() throws DataMigrationException, XWikiException { String hql = "SELECT DISTINCT doc.fullName FROM XWikiDocument doc, BaseObject obj WHERE doc.fullName = obj.name" + " AND obj.className = :className AND doc.fullName <> :template AND doc.fullName NOT IN " + "(SELECT DISTINCT doc2.fullName FROM XWikiDocument doc2, BaseObject obj2, StringProperty propPrettyName" + " WHERE doc2.fullName = obj2.name AND obj2.className = :className" + " AND propPrettyName.id = obj2.id AND propPrettyName.name = :propertyName)"; try { Query query = queryManager.createQuery(hql, Query.HQL); query.bindValue("className", String.format("%s.%s", XWiki.SYSTEM_SPACE, XWikiServerClassDocumentInitializer.DOCUMENT_NAME)); query.bindValue("propertyName", XWikiServerClassDocumentInitializer.FIELD_WIKIPRETTYNAME); query.bindValue("template", "XWiki.XWikiServerClassTemplate"); List<String> results = query.execute(); for (String result : results) { fixDocument(result); } } catch (QueryException e) { logger.error("Failed to perform a query on the main wiki.", e); } } }
WikiDescriptorMigrator extends AbstractHibernateDataMigration { @Override protected void hibernateMigrate() throws DataMigrationException, XWikiException { String hql = "SELECT DISTINCT doc.fullName FROM XWikiDocument doc, BaseObject obj WHERE doc.fullName = obj.name" + " AND obj.className = :className AND doc.fullName <> :template AND doc.fullName NOT IN " + "(SELECT DISTINCT doc2.fullName FROM XWikiDocument doc2, BaseObject obj2, StringProperty propPrettyName" + " WHERE doc2.fullName = obj2.name AND obj2.className = :className" + " AND propPrettyName.id = obj2.id AND propPrettyName.name = :propertyName)"; try { Query query = queryManager.createQuery(hql, Query.HQL); query.bindValue("className", String.format("%s.%s", XWiki.SYSTEM_SPACE, XWikiServerClassDocumentInitializer.DOCUMENT_NAME)); query.bindValue("propertyName", XWikiServerClassDocumentInitializer.FIELD_WIKIPRETTYNAME); query.bindValue("template", "XWiki.XWikiServerClassTemplate"); List<String> results = query.execute(); for (String result : results) { fixDocument(result); } } catch (QueryException e) { logger.error("Failed to perform a query on the main wiki.", e); } }  }
WikiDescriptorMigrator extends AbstractHibernateDataMigration { @Override protected void hibernateMigrate() throws DataMigrationException, XWikiException { String hql = "SELECT DISTINCT doc.fullName FROM XWikiDocument doc, BaseObject obj WHERE doc.fullName = obj.name" + " AND obj.className = :className AND doc.fullName <> :template AND doc.fullName NOT IN " + "(SELECT DISTINCT doc2.fullName FROM XWikiDocument doc2, BaseObject obj2, StringProperty propPrettyName" + " WHERE doc2.fullName = obj2.name AND obj2.className = :className" + " AND propPrettyName.id = obj2.id AND propPrettyName.name = :propertyName)"; try { Query query = queryManager.createQuery(hql, Query.HQL); query.bindValue("className", String.format("%s.%s", XWiki.SYSTEM_SPACE, XWikiServerClassDocumentInitializer.DOCUMENT_NAME)); query.bindValue("propertyName", XWikiServerClassDocumentInitializer.FIELD_WIKIPRETTYNAME); query.bindValue("template", "XWiki.XWikiServerClassTemplate"); List<String> results = query.execute(); for (String result : results) { fixDocument(result); } } catch (QueryException e) { logger.error("Failed to perform a query on the main wiki.", e); } }  @Override String getDescription(); @Override XWikiDBVersion getVersion(); @Override boolean shouldExecute(XWikiDBVersion startupVersion); }
WikiDescriptorMigrator extends AbstractHibernateDataMigration { @Override protected void hibernateMigrate() throws DataMigrationException, XWikiException { String hql = "SELECT DISTINCT doc.fullName FROM XWikiDocument doc, BaseObject obj WHERE doc.fullName = obj.name" + " AND obj.className = :className AND doc.fullName <> :template AND doc.fullName NOT IN " + "(SELECT DISTINCT doc2.fullName FROM XWikiDocument doc2, BaseObject obj2, StringProperty propPrettyName" + " WHERE doc2.fullName = obj2.name AND obj2.className = :className" + " AND propPrettyName.id = obj2.id AND propPrettyName.name = :propertyName)"; try { Query query = queryManager.createQuery(hql, Query.HQL); query.bindValue("className", String.format("%s.%s", XWiki.SYSTEM_SPACE, XWikiServerClassDocumentInitializer.DOCUMENT_NAME)); query.bindValue("propertyName", XWikiServerClassDocumentInitializer.FIELD_WIKIPRETTYNAME); query.bindValue("template", "XWiki.XWikiServerClassTemplate"); List<String> results = query.execute(); for (String result : results) { fixDocument(result); } } catch (QueryException e) { logger.error("Failed to perform a query on the main wiki.", e); } }  @Override String getDescription(); @Override XWikiDBVersion getVersion(); @Override boolean shouldExecute(XWikiDBVersion startupVersion);  }