use of org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor in project xwiki-platform by xwiki.
the class WikiDescriptorListener method onEvent.
@Override
public void onEvent(Event event, Object source, Object data) {
XWikiDocument document = (XWikiDocument) source;
// so then unregister them
if (event instanceof DocumentDeletedEvent || event instanceof DocumentUpdatedEvent) {
removeExistingDescriptor(document.getOriginalDocument());
}
// Register the new XWiki Server objects if any
List<BaseObject> serverClassObjects = document.getXObjects(SERVER_CLASS);
if (serverClassObjects != null && !serverClassObjects.isEmpty()) {
DefaultWikiDescriptor descriptor = this.builder.buildDescriptorObject(serverClassObjects, document);
if (descriptor != null) {
this.cache.add(descriptor);
this.cache.setWikiIds(null);
}
}
}
use of org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor in project xwiki-platform by xwiki.
the class DefaultWikiDescriptorBuilder method buildDescriptorObject.
@Override
public DefaultWikiDescriptor buildDescriptorObject(List<BaseObject> serverClassObjects, XWikiDocument document) {
List<BaseObject> normalizedServerClassObjects = normalizeServerClassObjects(serverClassObjects);
BaseObject mainServerClassObject = normalizedServerClassObjects.remove(0);
DefaultWikiDescriptor descriptor = extractWikiDescriptor(mainServerClassObject, document);
if (descriptor != null) {
// Create WikiAlias instances for the other XWikiServerClass objects
for (BaseObject serverClassObject : normalizedServerClassObjects) {
if (serverClassObject != null) {
String descriptorAlias = extractWikiAlias(serverClassObject);
descriptor.addAlias(descriptorAlias);
}
}
// load properties
descriptor.setMainPageReference(referenceResolver.resolve(mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_HOMEPAGE)));
descriptor.setPrettyName(mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_WIKIPRETTYNAME));
descriptor.setOwnerId(getFullReference(mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_OWNER), descriptor.getId()));
descriptor.setDescription(mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_DESCRIPTION));
// load the property groups
try {
WikiPropertyGroupManager wikiPropertyGroupManager = wikiPropertyGroupManagerProvider.get();
wikiPropertyGroupManager.loadForDescriptor(descriptor);
} catch (WikiPropertyGroupException e) {
logger.error("Failed to load wiki property groups for wiki [{}].", descriptor.getId(), e);
}
}
return descriptor;
}
use of org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor in project xwiki-platform by xwiki.
the class DefaultWikiCreatorTest method create.
@Test
public void create() throws Exception {
// Other mocks
DefaultWikiDescriptor descriptor = new DefaultWikiDescriptor("wikiid1", "wikialias1");
XWikiDocument descriptorDocument = mock(XWikiDocument.class);
when(wikiDescriptorBuilder.save(eq(descriptor))).thenReturn(descriptorDocument);
when(wikiDescriptorManager.getById("wikiid1")).thenReturn(descriptor);
when(store.isWikiNameAvailable(any(String.class), any(XWikiContext.class))).thenReturn(true);
// Create
WikiDescriptor newWikiDescriptor = this.mocker.getComponentUnderTest().create("wikiid1", "wikialias1");
assertNotNull(newWikiDescriptor);
// Verify that the wiki descriptor is an instance of DefaultWikiDescriptor
assertTrue(newWikiDescriptor instanceof DefaultWikiDescriptor);
// Verify that the wiki has been created
verify(store).createWiki(eq("wikiid1"), any(XWikiContext.class));
// Verify that the wiki has been updated
verify(xwiki).initializeWiki(eq("wikiid1"), eq(true), any(XWikiContext.class));
// Verify that the descriptor document has been saved
verify(wikiDescriptorBuilder).save(eq(descriptor));
// Verify that the descriptor has been reloaded after being saved
assertTrue(descriptor == newWikiDescriptor);
}
use of org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor in project xwiki-platform by xwiki.
the class DefaultWikiDeleterTest method deleteWiki.
@Test
public void deleteWiki() throws Exception {
// Mock
DefaultWikiDescriptor descriptor = new DefaultWikiDescriptor("wikiid", "wikialias");
descriptor.addAlias("wikialias2");
XWikiDocument descriptorDocument = mock(XWikiDocument.class);
when(descriptorDocumentHelper.getDocumentFromWikiId("wikiid")).thenReturn(descriptorDocument);
// Delete
this.mocker.getComponentUnderTest().delete("wikiid");
// Verify that the database has been deleted
verify(store).deleteWiki(eq("wikiid"), any(XWikiContext.class));
// Verify that the descriptor document has been deleted
verify(xwiki).deleteDocument(eq(descriptorDocument), any(XWikiContext.class));
}
use of org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor in project xwiki-platform by xwiki.
the class DefaultWikiManagerTest method copyWhenWikiAvailable.
@Test
public void copyWhenWikiAvailable() throws Exception {
// The wiki does not already exist
when(wikiDescriptorManager.exists("wikiid1")).thenReturn(false);
// The new id is valid
when(xwiki.Param("xwiki.virtual.reserved_wikis")).thenReturn("forbidden");
// The wiki name is available
when(store.isWikiNameAvailable(eq("wikiid1"), any(XWikiContext.class))).thenReturn(true);
// Other mocks
DefaultWikiDescriptor descriptor = new DefaultWikiDescriptor("wikiid1", "wikialias1");
when(wikiCreator.create("wikiid1", "wikialias1")).thenReturn(descriptor);
// Copy
WikiDescriptor newWikiDescriptor = this.mocker.getComponentUnderTest().copy("wikiid", "wikiid1", "wikialias1", true, true, true);
assertNotNull(newWikiDescriptor);
// Verify that the wiki has been created
verify(wikiCreator).create("wikiid1", "wikialias1");
// Verify that the wiki has been copied
verify(wikiCopier).copyDocuments(eq("wikiid"), eq("wikiid1"), eq(true));
// Verify that deleted documents has been copied too
verify(wikiCopier).copyDeletedDocuments(eq("wikiid"), eq("wikiid1"));
// Verify that events has been sent
verify(observationManager).notify(new WikiCopiedEvent("wikiid", "wikiid1"), "wikiid", xcontext);
}
Aggregations