Search in sources :

Example 1 with WikiCopiedEvent

use of org.xwiki.bridge.event.WikiCopiedEvent in project xwiki-platform by xwiki.

the class TemplateWikiProvisioningJob method runInternal.

@Override
protected void runInternal() throws Exception {
    WikiProvisioningJobRequest request = getRequest();
    if (!(request.getProvisioningJobParameter() instanceof String)) {
        throw new Exception("The provisioning parameter is not a valid String.");
    }
    XWikiContext xcontext = xcontextProvider.get();
    String wikiId = request.getWikiId();
    String templateId = (String) request.getProvisioningJobParameter();
    // Set the user actually doing the action in the context
    xcontext.setUserReference(request.getProvisioningUser());
    try {
        observationManager.notify(new WikiProvisioningEvent(wikiId), wikiId, xcontext);
        wikiCopier.copyDocuments(templateId, wikiId, false);
        observationManager.notify(new WikiProvisionedEvent(wikiId), wikiId, xcontext);
        observationManager.notify(new WikiCopiedEvent(templateId, wikiId), templateId, xcontext);
    } catch (WikiManagerException e) {
        logger.error("Failed to provision wiki [{}] from template [{}].", wikiId, templateId, e);
        observationManager.notify(new WikiProvisioningFailedEvent(wikiId), wikiId, xcontext);
    }
}
Also used : WikiProvisioningFailedEvent(org.xwiki.bridge.event.WikiProvisioningFailedEvent) WikiProvisionedEvent(org.xwiki.bridge.event.WikiProvisionedEvent) WikiCopiedEvent(org.xwiki.bridge.event.WikiCopiedEvent) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiProvisioningEvent(org.xwiki.bridge.event.WikiProvisioningEvent) WikiProvisioningJobRequest(org.xwiki.wiki.provisioning.WikiProvisioningJobRequest) XWikiContext(com.xpn.xwiki.XWikiContext) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException)

Example 2 with WikiCopiedEvent

use of org.xwiki.bridge.event.WikiCopiedEvent in project xwiki-platform by xwiki.

the class WikiCopiedEventListenerTest method testCopyOneExtension.

@Test
public void testCopyOneExtension() throws InstallException {
    InstalledExtension extensionDependency1 = this.installedExtensionRepository.installExtension(this.localExtensionDependency1, "wiki:source", false);
    InstalledExtension extension1 = this.installedExtensionRepository.installExtension(this.localExtension1, "wiki:source", false);
    Assert.assertFalse(extension1.isInstalled("wiki:target"));
    Assert.assertFalse(extensionDependency1.isInstalled("wiki:target"));
    this.observation.notify(new WikiCopiedEvent("source", "target"), null, null);
    Assert.assertTrue(extension1.isInstalled("wiki:target"));
    Assert.assertTrue(extensionDependency1.isInstalled("wiki:target"));
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) WikiCopiedEvent(org.xwiki.bridge.event.WikiCopiedEvent) Test(org.junit.Test)

Example 3 with WikiCopiedEvent

use of org.xwiki.bridge.event.WikiCopiedEvent in project xwiki-platform by xwiki.

the class XWiki method copyWiki.

/**
 * Copy an entire wiki to a target wiki.
 *
 * @param sourceWiki the source wiki identifier
 * @param targetWiki the target wiki identifier
 * @param locale the locale to copy
 * @param clean clean the target wiki before copying
 * @param context see {@link XWikiContext}
 * @return the number of copied documents
 * @throws XWikiException failed to copy wiki
 * @deprecated since 5.3, use {@link WikiManager#copy(String, String, String, boolean, boolean, boolean)} instead
 */
@Deprecated
public int copyWiki(String sourceWiki, String targetWiki, String locale, boolean clean, XWikiContext context) throws XWikiException {
    int documents = copySpaceBetweenWikis(null, sourceWiki, targetWiki, locale, clean, context);
    ObservationManager om = getObservationManager();
    if (om != null) {
        om.notify(new WikiCopiedEvent(sourceWiki, targetWiki), sourceWiki, context);
    }
    return documents;
}
Also used : WikiCopiedEvent(org.xwiki.bridge.event.WikiCopiedEvent) ObservationManager(org.xwiki.observation.ObservationManager)

Example 4 with WikiCopiedEvent

use of org.xwiki.bridge.event.WikiCopiedEvent in project xwiki-platform by xwiki.

the class DefaultWikiManager method copy.

@Override
public WikiDescriptor copy(String fromWikiId, String newWikiId, String newWikiAlias, boolean copyHistory, boolean copyRecycleBin, boolean failOnExist) throws WikiManagerException {
    WikiDescriptor newWiki = create(newWikiId, newWikiAlias, failOnExist);
    wikiCopier.copyDocuments(fromWikiId, newWikiId, copyHistory);
    if (copyRecycleBin) {
        wikiCopier.copyDeletedDocuments(fromWikiId, newWikiId);
    }
    observationManager.notify(new WikiCopiedEvent(fromWikiId, newWikiId), fromWikiId, xcontextProvider.get());
    return newWiki;
}
Also used : WikiCopiedEvent(org.xwiki.bridge.event.WikiCopiedEvent) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor)

Example 5 with WikiCopiedEvent

use of org.xwiki.bridge.event.WikiCopiedEvent in project xwiki-platform by xwiki.

the class ProvisionWikiStep method execute.

@Override
public void execute(WikiCreationRequest request) throws WikiCreationException {
    try {
        if (request.getWikiSource() == null) {
            // No source is defined, we let the wiki empty and DW will do the rest
            return;
        }
        switch(request.getWikiSource()) {
            case EXTENSION:
                sendWikiProvisioningEvent(request);
                extensionInstaller.installExtension(request.getWikiId(), request.getExtensionId());
                sendWikiProvisionedEvent(request);
                break;
            case TEMPLATE:
                sendWikiProvisioningEvent(request);
                wikiCopier.copyDocuments(request.getTemplateId(), request.getWikiId(), false);
                observationManager.notify(new WikiCopiedEvent(request.getTemplateId(), request.getWikiId()), request.getTemplateId(), xcontextProvider.get());
                sendWikiProvisionedEvent(request);
                break;
            default:
                // No source is defined, we let the wiki empty and DW will do the rest
                break;
        }
    } catch (WikiManagerException | WikiCreationException e) {
        observationManager.notify(new WikiProvisioningFailedEvent(request.getWikiId()), request.getWikiId(), xcontextProvider.get());
        throw new WikiCreationException(String.format("Failed to provision the wiki [%s].", request.getWikiId()), e);
    }
}
Also used : WikiProvisioningFailedEvent(org.xwiki.bridge.event.WikiProvisioningFailedEvent) WikiCopiedEvent(org.xwiki.bridge.event.WikiCopiedEvent) WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException)

Aggregations

WikiCopiedEvent (org.xwiki.bridge.event.WikiCopiedEvent)7 Test (org.junit.Test)3 XWikiContext (com.xpn.xwiki.XWikiContext)2 WikiProvisionedEvent (org.xwiki.bridge.event.WikiProvisionedEvent)2 WikiProvisioningEvent (org.xwiki.bridge.event.WikiProvisioningEvent)2 WikiProvisioningFailedEvent (org.xwiki.bridge.event.WikiProvisioningFailedEvent)2 WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)2 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)2 InstalledExtension (org.xwiki.extension.InstalledExtension)1 ObservationManager (org.xwiki.observation.ObservationManager)1 WikiCreationException (org.xwiki.platform.wiki.creationjob.WikiCreationException)1 WikiCreationRequest (org.xwiki.platform.wiki.creationjob.WikiCreationRequest)1 DefaultWikiDescriptor (org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor)1 WikiProvisioningJobRequest (org.xwiki.wiki.provisioning.WikiProvisioningJobRequest)1