Search in sources :

Example 1 with CancelableEvent

use of org.xwiki.observation.event.CancelableEvent in project xwiki-platform by xwiki.

the class NestedScriptMacroValidatorTest method testNoNestedScriptInHtml.

@Test
public void testNoNestedScriptInHtml() throws Exception {
    MacroTransformationContext context = buildContext("script", "html", "script");
    CancelableEvent event = new ScriptEvaluatingEvent();
    this.validator.onEvent(event, context, null);
    Assert.assertTrue(event.isCanceled());
}
Also used : ScriptEvaluatingEvent(org.xwiki.script.event.ScriptEvaluatingEvent) MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) CancelableEvent(org.xwiki.observation.event.CancelableEvent) Test(org.junit.Test)

Example 2 with CancelableEvent

use of org.xwiki.observation.event.CancelableEvent in project xwiki-platform by xwiki.

the class NestedScriptMacroValidatorTest method testNoNestedScript.

@Test
public void testNoNestedScript() throws Exception {
    MacroTransformationContext context = buildContext("script", "script");
    CancelableEvent event = new ScriptEvaluatingEvent();
    this.validator.onEvent(event, context, null);
    Assert.assertTrue(event.isCanceled());
}
Also used : ScriptEvaluatingEvent(org.xwiki.script.event.ScriptEvaluatingEvent) MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) CancelableEvent(org.xwiki.observation.event.CancelableEvent) Test(org.junit.Test)

Example 3 with CancelableEvent

use of org.xwiki.observation.event.CancelableEvent in project xwiki-platform by xwiki.

the class NestedScriptMacroValidatorTest method testNestedScriptMacroEnabledInterceptsNestedChain.

@Test
public void testNestedScriptMacroEnabledInterceptsNestedChain() throws Exception {
    MacroTransformationContext context = buildContext("script", "nestedscriptmacroenabled", "script");
    CancelableEvent event = new ScriptEvaluatingEvent();
    this.validator.onEvent(event, context, null);
    Assert.assertFalse(event.isCanceled());
}
Also used : ScriptEvaluatingEvent(org.xwiki.script.event.ScriptEvaluatingEvent) MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) CancelableEvent(org.xwiki.observation.event.CancelableEvent) Test(org.junit.Test)

Example 4 with CancelableEvent

use of org.xwiki.observation.event.CancelableEvent in project xwiki-platform by xwiki.

the class NestedScriptMacroValidatorTest method testIncludeInterceptsNestedChain.

@Test
public void testIncludeInterceptsNestedChain() throws Exception {
    MacroTransformationContext context = buildContext("script", "include", "script");
    CancelableEvent event = new ScriptEvaluatingEvent();
    this.validator.onEvent(event, context, null);
    Assert.assertFalse(event.isCanceled());
}
Also used : ScriptEvaluatingEvent(org.xwiki.script.event.ScriptEvaluatingEvent) MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) CancelableEvent(org.xwiki.observation.event.CancelableEvent) Test(org.junit.Test)

Example 5 with CancelableEvent

use of org.xwiki.observation.event.CancelableEvent in project xwiki-platform by xwiki.

the class DocumentsDeletingListener method onEvent.

@Override
public void onEvent(Event event, Object source, Object data) {
    Job job = (Job) source;
    if (!job.getRequest().isInteractive()) {
        logger.warn("XAR Extension Documents Deleting Listener will not check the document in non-interactive mode.");
        return;
    }
    // Check if some pages belong to extensions
    Map<EntityReference, EntitySelection> concernedEntities = (Map<EntityReference, EntitySelection>) data;
    ExtensionBreakingQuestion question = new ExtensionBreakingQuestion(concernedEntities);
    for (EntitySelection entitySelection : concernedEntities.values()) {
        if (entitySelection.getEntityReference() instanceof DocumentReference) {
            checkIfPageBelongToExtensions(entitySelection, question);
        }
    }
    // Ask a confirmation to the user if some pages belong to extensions
    if (!question.getExtensions().isEmpty()) {
        // Conservative choice: we let the user enable the pages to delete.
        question.unselectAll();
        try {
            // The user can modify the question so it could disable some EntitySelection.
            // We add a timeout because when a refactoring job is running, it prevents others to run.
            // 5 minutes is probably enough for the user to decide if the process should go on.
            boolean ack = job.getStatus().ask(question, 5, TimeUnit.MINUTES);
            if (!ack) {
                // Without any confirmation, we must cancel the operation.
                String message = "The question has been asked, however no answer has been received.";
                this.logger.warn(message);
                CancelableEvent cancelableEvent = (CancelableEvent) event;
                cancelableEvent.cancel(message);
            }
        } catch (InterruptedException e) {
            this.logger.warn("Confirm question has been interrupted.");
            CancelableEvent cancelableEvent = (CancelableEvent) event;
            cancelableEvent.cancel("Question has been interrupted.");
        }
    }
}
Also used : EntitySelection(org.xwiki.refactoring.job.question.EntitySelection) EntityReference(org.xwiki.model.reference.EntityReference) ExtensionBreakingQuestion(org.xwiki.extension.xar.internal.delete.question.ExtensionBreakingQuestion) Job(org.xwiki.job.Job) Map(java.util.Map) CancelableEvent(org.xwiki.observation.event.CancelableEvent) DocumentReference(org.xwiki.model.reference.DocumentReference)

Aggregations

CancelableEvent (org.xwiki.observation.event.CancelableEvent)6 Test (org.junit.Test)4 MacroTransformationContext (org.xwiki.rendering.transformation.MacroTransformationContext)4 ScriptEvaluatingEvent (org.xwiki.script.event.ScriptEvaluatingEvent)4 DocumentReference (org.xwiki.model.reference.DocumentReference)2 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 XWikiAttachmentToRemove (com.xpn.xwiki.doc.XWikiDocument.XWikiAttachmentToRemove)1 ParseGroovyFromString (com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString)1 IncludeServletAsString (com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 Date (java.util.Date)1 Map (java.util.Map)1 NamingException (javax.naming.NamingException)1 URIException (org.apache.commons.httpclient.URIException)1 HibernateException (org.hibernate.HibernateException)1 DocumentCreatedEvent (org.xwiki.bridge.event.DocumentCreatedEvent)1 DocumentCreatingEvent (org.xwiki.bridge.event.DocumentCreatingEvent)1