Search in sources :

Example 11 with ActionResult

use of com.cognifide.apm.api.actions.ActionResult in project APM by Cognifide.

the class ForAuthorizable method process.

public ActionResult process(final Context context) {
    ActionResult actionResult = context.createActionResult();
    try {
        if (shouldBeGroup) {
            Group group = context.getAuthorizableManager().getGroup(id);
            context.setCurrentAuthorizable(group);
            actionResult.logMessage("Group with id: " + group.getID() + " set as current authorizable");
        } else {
            User user = context.getAuthorizableManager().getUser(id);
            context.setCurrentAuthorizable(user);
            actionResult.logMessage("User with id: " + user.getID() + " set as current authorizable");
        }
    } catch (RepositoryException | ActionExecutionException e) {
        actionResult.logError(MessagingUtils.createMessage(e));
    }
    return actionResult;
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) User(org.apache.jackrabbit.api.security.user.User) ActionResult(com.cognifide.apm.api.actions.ActionResult) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.apm.api.exceptions.ActionExecutionException)

Example 12 with ActionResult

use of com.cognifide.apm.api.actions.ActionResult in project APM by Cognifide.

the class CheckAuthorizableExists method process.

public ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = context.createActionResult();
    try {
        Authorizable authorizable = null;
        if (shouldBeGroup) {
            authorizable = context.getAuthorizableManager().getGroupIfExists(id);
        } else {
            authorizable = context.getAuthorizableManager().getUserIfExists(id);
        }
        if (checkIfAuthIsNull(execute, actionResult, authorizable)) {
            return actionResult;
        }
        checkPath(actionResult, authorizable, execute);
    } catch (RepositoryException | ActionExecutionException e) {
        actionResult.logError(MessagingUtils.createMessage(e));
    }
    return actionResult;
}
Also used : ActionResult(com.cognifide.apm.api.actions.ActionResult) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.apm.api.exceptions.ActionExecutionException)

Example 13 with ActionResult

use of com.cognifide.apm.api.actions.ActionResult in project APM by Cognifide.

the class SessionSave method process.

private ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = context.createActionResult();
    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.apm.api.actions.ActionResult) SessionSavingMode(com.cognifide.apm.api.actions.SessionSavingMode) SessionSavingPolicy(com.cognifide.apm.api.actions.SessionSavingPolicy)

Example 14 with ActionResult

use of com.cognifide.apm.api.actions.ActionResult in project APM by Cognifide.

the class ScriptManagerImpl method execute.

private Progress execute(Script script, final ExecutionMode 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();
    LOG.info(String.format("Script execution started: %s [%s]", path, mode));
    final Progress progress = new ProgressImpl(resolver.getUserID());
    final ActionExecutor actionExecutor = createExecutor(mode, resolver);
    final Context context = actionExecutor.getContext();
    final SessionSavingPolicy savingPolicy = context.getSavingPolicy();
    eventManager.trigger(new ScriptLaunchedEvent(script, mode));
    ScriptRunner scriptRunner = new ScriptRunner(scriptFinder, resolver, mode == ExecutionMode.VALIDATION, (executionContext, commandName, arguments) -> {
        try {
            context.setCurrentAuthorizable(executionContext.getAuthorizable());
            ActionDescriptor descriptor = actionFactory.evaluate(commandName, arguments);
            ActionResult result = actionExecutor.execute(descriptor);
            executionContext.setAuthorizable(context.getCurrentAuthorizableIfExists());
            progress.addEntry(descriptor, result);
            if ((Status.ERROR != result.getStatus()) || (ExecutionMode.DRY_RUN == mode)) {
                savingPolicy.save(context.getSession(), SessionSavingMode.EVERY_ACTION);
            }
            return result.getStatus();
        } catch (RepositoryException | ActionCreationException e) {
            LOG.error("Error while processing command: {}", commandName, e);
            progress.addEntry(Status.ERROR, e.getMessage(), commandName);
            return Status.ERROR;
        }
    });
    try {
        Map<String, String> definitions = new HashMap<>();
        definitions.putAll(getPredefinedDefinitions());
        definitions.putAll(customDefinitions);
        scriptRunner.execute(script, progress, definitions);
    } catch (RuntimeException e) {
        progress.addEntry(Status.ERROR, e.getMessage());
    }
    if (progress.isSuccess()) {
        savingPolicy.save(context.getSession(), SessionSavingMode.SINGLE);
    }
    return progress;
}
Also used : Context(com.cognifide.apm.api.actions.Context) ProgressImpl(com.cognifide.apm.core.progress.ProgressImpl) ActionExecutor(com.cognifide.apm.core.actions.executor.ActionExecutor) Progress(com.cognifide.apm.core.logger.Progress) HashMap(java.util.HashMap) ActionDescriptor(com.cognifide.apm.core.actions.ActionDescriptor) ScriptLaunchedEvent(com.cognifide.apm.core.services.event.ApmEvent.ScriptLaunchedEvent) RepositoryException(javax.jcr.RepositoryException) ScriptRunner(com.cognifide.apm.core.grammar.ScriptRunner) ActionCreationException(com.cognifide.apm.api.exceptions.ActionCreationException) ActionResult(com.cognifide.apm.api.actions.ActionResult) SessionSavingPolicy(com.cognifide.apm.api.actions.SessionSavingPolicy) ExecutionException(com.cognifide.apm.api.exceptions.ExecutionException)

Example 15 with ActionResult

use of com.cognifide.apm.api.actions.ActionResult in project APM by Cognifide.

the class CheckNotExists method process.

private ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = context.createActionResult();
    List<String> errors = new ArrayList<>();
    boolean checkFailed = checkAuthorizables(context, actionResult, errors);
    if (execute && checkFailed) {
        actionResult.logError(ActionUtils.ASSERTION_FAILED_MSG);
        return actionResult;
    }
    logErrors(actionResult, errors);
    return actionResult;
}
Also used : ActionResult(com.cognifide.apm.api.actions.ActionResult) ArrayList(java.util.ArrayList)

Aggregations

ActionResult (com.cognifide.apm.api.actions.ActionResult)30 RepositoryException (javax.jcr.RepositoryException)23 ActionExecutionException (com.cognifide.apm.api.exceptions.ActionExecutionException)21 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)16 ArrayList (java.util.ArrayList)10 Group (org.apache.jackrabbit.api.security.user.Group)10 User (org.apache.jackrabbit.api.security.user.User)5 Action (com.cognifide.apm.api.actions.Action)4 PathNotFoundException (javax.jcr.PathNotFoundException)3 Context (com.cognifide.apm.api.actions.Context)2 SessionSavingPolicy (com.cognifide.apm.api.actions.SessionSavingPolicy)2 RemoveParents (com.cognifide.apm.main.actions.removeparents.RemoveParents)2 PermissionActionHelper (com.cognifide.apm.main.permissions.PermissionActionHelper)2 PermissionException (com.cognifide.apm.main.permissions.exceptions.PermissionException)2 SessionSavingMode (com.cognifide.apm.api.actions.SessionSavingMode)1 ActionCreationException (com.cognifide.apm.api.exceptions.ActionCreationException)1 ExecutionException (com.cognifide.apm.api.exceptions.ExecutionException)1 ActionDescriptor (com.cognifide.apm.core.actions.ActionDescriptor)1 ActionExecutor (com.cognifide.apm.core.actions.executor.ActionExecutor)1 ScriptRunner (com.cognifide.apm.core.grammar.ScriptRunner)1