Search in sources :

Example 26 with ActionResult

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

the class DeleteGroup method process.

private ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = context.createActionResult();
    List<String> errors = new ArrayList<>();
    LOGGER.info(String.format("Removing groups with ids = %s", StringUtils.join(ids, ", ")));
    for (String id : ids) {
        try {
            Group group = context.getAuthorizableManager().getGroupIfExists(id);
            if (group != null) {
                context.getAuthorizableManager().markAuthorizableAsRemoved(group);
                if (execute) {
                    context.getAuthorizableManager().removeGroup(group);
                }
                actionResult.logMessage("Group with id: " + id + " removed");
            }
        } 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) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.apm.api.exceptions.ActionExecutionException)

Example 27 with ActionResult

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

the class RemoveUser method process.

private ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = context.createActionResult();
    List<String> errors = new ArrayList<>();
    LOGGER.info(String.format("Removing users with ids = %s", StringUtils.join(ids, ", ")));
    for (String id : ids) {
        try {
            User user = context.getAuthorizableManager().getUserIfExists(id);
            if (user != null) {
                context.getAuthorizableManager().markAuthorizableAsRemoved(user);
                if (execute) {
                    context.getAuthorizableManager().removeUser(user);
                }
                actionResult.logMessage("User with id: " + id + " removed");
            }
        } 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 : User(org.apache.jackrabbit.api.security.user.User) ActionResult(com.cognifide.apm.api.actions.ActionResult) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.apm.api.exceptions.ActionExecutionException)

Example 28 with ActionResult

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

the class RemoveChildren method process.

private ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = context.createActionResult();
    Group group = null;
    try {
        group = context.getCurrentGroup();
        actionResult.setAuthorizable(group.getID());
        LOGGER.info(String.format("Removing authorizables %s from 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().getAuthorizableIfExists(authorizableId);
            if (authorizable == null) {
                actionResult.logWarning(MessagingUtils.authorizableNotExists(authorizableId));
                continue;
            }
            if (execute) {
                group.removeMember(authorizable);
            }
            actionResult.logMessage(MessagingUtils.removedFromGroup(authorizableId, group.getID()));
        } catch (RepositoryException 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 29 with ActionResult

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

the class ClearFromGroupDetacher method detachAuthorizableFromParents.

public ActionResult detachAuthorizableFromParents() {
    ActionResult actionResult = context.createActionResult();
    try {
        Authorizable currentAuthorizable = context.getCurrentAuthorizable();
        Iterator<Group> groups = getGroupParents(actionResult, currentAuthorizable);
        LOGGER.info(String.format("Removing all memberships of authorizable with id = %s", currentAuthorizable.getID()));
        detachFromParents(actionResult, currentAuthorizable, groups);
    } catch (RepositoryException | ActionExecutionException e) {
        actionResult.logError(MessagingUtils.createMessage(e));
    }
    return actionResult;
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) 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 30 with ActionResult

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

the class ClearFromGroupDetacher method detachMembersFromGroup.

public ActionResult detachMembersFromGroup() {
    ActionResult actionResult = context.createActionResult();
    try {
        Authorizable authorizable = context.getCurrentAuthorizable();
        if (authorizable.isGroup()) {
            final Group group = context.getCurrentGroup();
            LOGGER.info(String.format("Removing all members of group with id = %s", group.getID()));
            Iterator<Authorizable> groupMembers = getGroupMembers(actionResult, group);
            detachAllMembers(actionResult, group, groupMembers);
        } else {
            actionResult.logError("Child members can only be removed from groups");
        }
    } catch (RepositoryException | ActionExecutionException e) {
        actionResult.logError(MessagingUtils.createMessage(e));
    }
    return actionResult;
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) 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)

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