Search in sources :

Example 1 with ActionResult

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

the class CompositeAction method simulate.

@Override
public ActionResult simulate(Context context) throws ActionExecutionException {
    ActionResult result = context.createActionResult();
    List<ActionResult> actionResults = Lists.newArrayListWithCapacity(actions.size());
    for (Action action : actions) {
        actionResults.add(action.simulate(context));
    }
    return result.merge(actionResults);
}
Also used : Action(com.cognifide.apm.api.actions.Action) ActionResult(com.cognifide.apm.api.actions.ActionResult)

Example 2 with ActionResult

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

the class AddChildren method process.

private ActionResult process(Context context, boolean execute) {
    ActionResult actionResult = context.createActionResult();
    Group group = null;
    try {
        group = context.getCurrentGroup();
        actionResult.setAuthorizable(group.getID());
        LOGGER.info(String.format("Adding authorizables %s to group with id = %s", StringUtils.join(authorizableIds, ", "), group.getID()));
    } catch (ActionExecutionException e) {
        actionResult.logError(MessagingUtils.createMessage(e));
        return actionResult;
    } catch (RepositoryException e) {
        actionResult.logError(MessagingUtils.createMessage(e));
        return actionResult;
    }
    List<String> errors = new ArrayList<>();
    for (String authorizableId : authorizableIds) {
        try {
            Authorizable authorizable = context.getAuthorizableManager().getAuthorizable(authorizableId);
            if (authorizable.isGroup()) {
                ActionUtils.checkCyclicRelations(group, (Group) authorizable);
            }
            if (execute) {
                group.addMember(authorizable);
            }
            actionResult.logMessage(MessagingUtils.addedToGroup(authorizableId, group.getID()));
        } catch (RepositoryException | ActionExecutionException e) {
            errors.add(MessagingUtils.createMessage(e));
        }
    }
    if (!errors.isEmpty()) {
        for (String error : errors) {
            actionResult.logError(error);
        }
        actionResult.logError("Execution interrupted");
    }
    return actionResult;
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) ActionResult(com.cognifide.apm.api.actions.ActionResult) ArrayList(java.util.ArrayList) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.apm.api.exceptions.ActionExecutionException)

Example 3 with ActionResult

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

the class Purge method purge.

private void purge(final Context context, final ActionResult actionResult) throws RepositoryException, ActionExecutionException {
    NodeIterator iterator = getPermissions(context);
    String normalizedPath = normalizePath(path);
    while (iterator != null && iterator.hasNext()) {
        Node node = iterator.nextNode();
        if (node.hasProperty(PermissionConstants.REP_ACCESS_CONTROLLED_PATH)) {
            String parentPath = node.getProperty(PermissionConstants.REP_ACCESS_CONTROLLED_PATH).getString();
            String normalizedParentPath = normalizePath(parentPath);
            boolean isUsersPermission = parentPath.startsWith(context.getCurrentAuthorizable().getPath());
            if (StringUtils.startsWith(normalizedParentPath, normalizedPath) && !isUsersPermission) {
                RemoveAll removeAll = new RemoveAll(parentPath);
                ActionResult removeAllResult = removeAll.execute(context);
                if (Status.ERROR.equals(removeAllResult.getStatus())) {
                    copyErrorMessages(removeAllResult, actionResult);
                }
            }
        }
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) ActionResult(com.cognifide.apm.api.actions.ActionResult) Node(javax.jcr.Node)

Example 4 with ActionResult

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

the class CheckExcludes method process.

private ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = context.createActionResult();
    Group group = tryGetGroup(context, actionResult);
    if (group == null) {
        return actionResult;
    }
    List<String> errors = new ArrayList<>();
    boolean checkFailed = checkMembers(context, actionResult, group, errors);
    if (execute && checkFailed) {
        actionResult.logError(ActionUtils.ASSERTION_FAILED_MSG);
        return actionResult;
    }
    ActionUtils.logErrors(errors, actionResult);
    return actionResult;
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) ActionResult(com.cognifide.apm.api.actions.ActionResult) ArrayList(java.util.ArrayList)

Example 5 with ActionResult

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

the class CheckIncludes method process.

private ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = context.createActionResult();
    Group authorizable = tryGetGroup(context, actionResult);
    if (authorizable == null) {
        return actionResult;
    }
    List<String> errors = new ArrayList<>();
    boolean checkFailed = checkMembers(context, actionResult, authorizable, errors);
    if (execute && checkFailed) {
        actionResult.logError(ActionUtils.ASSERTION_FAILED_MSG);
        return actionResult;
    }
    ActionUtils.logErrors(errors, actionResult);
    return actionResult;
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) 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