Search in sources :

Example 1 with SessionSavingPolicy

use of com.cognifide.cq.cqsm.core.sessions.SessionSavingPolicy in project APM by Cognifide.

the class ScriptManagerImpl method execute.

private Progress execute(Script script, final Mode mode, Map<String, String> customDefinitions, ResourceResolver resolver) throws ExecutionException, RepositoryException {
    if (script == null) {
        throw new ExecutionException("Script is not specified");
    }
    if (mode == null) {
        throw new ExecutionException("Execution mode is not specified");
    }
    final String path = script.getPath();
    actionFactory.update();
    LOG.info(String.format("Script execution started: %s [%s]", path, mode));
    Progress progress = new ProgressImpl(resolver.getUserID());
    final List<ActionDescriptor> descriptors = parseAllDescriptors(script, customDefinitions, resolver);
    final ActionExecutor actionExecutor = createExecutor(mode, resolver);
    final Context context = actionExecutor.getContext();
    final SessionSavingPolicy savingPolicy = context.getSavingPolicy();
    eventManager.trigger(Event.BEFORE_EXECUTE, script, mode, progress);
    for (ActionDescriptor descriptor : descriptors) {
        ActionResult result = actionExecutor.execute(descriptor);
        progress.addEntry(descriptor, result);
        if ((Status.ERROR == result.getStatus()) && (Mode.DRY_RUN != mode)) {
            eventManager.trigger(Event.AFTER_EXECUTE, script, mode, progress);
            return progress;
        }
        savingPolicy.save(context.getSession(), SessionSavingMode.EVERY_ACTION);
    }
    savingPolicy.save(context.getSession(), SessionSavingMode.SINGLE);
    eventManager.trigger(Event.AFTER_EXECUTE, script, mode, progress);
    return progress;
}
Also used : Context(com.cognifide.cq.cqsm.api.executors.Context) ProgressImpl(com.cognifide.cq.cqsm.core.progress.ProgressImpl) ActionExecutor(com.cognifide.cq.cqsm.core.actions.executor.ActionExecutor) Progress(com.cognifide.cq.cqsm.api.logger.Progress) ActionResult(com.cognifide.cq.cqsm.api.actions.ActionResult) ActionDescriptor(com.cognifide.cq.cqsm.api.actions.ActionDescriptor) SessionSavingPolicy(com.cognifide.cq.cqsm.core.sessions.SessionSavingPolicy) ExecutionException(com.cognifide.cq.cqsm.api.exceptions.ExecutionException)

Example 2 with SessionSavingPolicy

use of com.cognifide.cq.cqsm.core.sessions.SessionSavingPolicy in project APM by Cognifide.

the class SessionSave method process.

private ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = new ActionResult();
    if (execute) {
        try {
            SessionSavingMode savingMode = SessionSavingMode.valueOfMode(mode);
            SessionSavingPolicy savingPolicy = context.getSavingPolicy();
            savingPolicy.setMode(savingMode);
            actionResult.logMessage("Session saving mode set to: " + mode);
        } catch (IllegalArgumentException e) {
            actionResult.logError(MessagingUtils.createMessage(e));
        }
    }
    return actionResult;
}
Also used : ActionResult(com.cognifide.cq.cqsm.api.actions.ActionResult) SessionSavingMode(com.cognifide.cq.cqsm.core.sessions.SessionSavingMode) SessionSavingPolicy(com.cognifide.cq.cqsm.core.sessions.SessionSavingPolicy)

Aggregations

ActionResult (com.cognifide.cq.cqsm.api.actions.ActionResult)2 SessionSavingPolicy (com.cognifide.cq.cqsm.core.sessions.SessionSavingPolicy)2 ActionDescriptor (com.cognifide.cq.cqsm.api.actions.ActionDescriptor)1 ExecutionException (com.cognifide.cq.cqsm.api.exceptions.ExecutionException)1 Context (com.cognifide.cq.cqsm.api.executors.Context)1 Progress (com.cognifide.cq.cqsm.api.logger.Progress)1 ActionExecutor (com.cognifide.cq.cqsm.core.actions.executor.ActionExecutor)1 ProgressImpl (com.cognifide.cq.cqsm.core.progress.ProgressImpl)1 SessionSavingMode (com.cognifide.cq.cqsm.core.sessions.SessionSavingMode)1