Search in sources :

Example 1 with RemoveParents

use of com.cognifide.apm.main.actions.removeparents.RemoveParents in project APM by Cognifide.

the class DestroyUser method execute.

@Override
public ActionResult execute(Context context) throws ActionExecutionException {
    ActionResult actionResult;
    try {
        User user = context.getAuthorizableManager().getUser(userId);
        // local context is used here to not override current authorizable in given context
        Context localContext = context.newContext();
        localContext.setCurrentAuthorizable(user);
        Action removeFromGroups = new RemoveParents(getGroups(user));
        ActionResult purgeResult = purge.execute(localContext);
        ActionResult removeFromGroupsResult = removeFromGroups.execute(localContext);
        ActionResult removeResult = remove.execute(localContext);
        actionResult = purgeResult.merge(removeFromGroupsResult, removeResult);
        actionResult.setAuthorizable(context.getCurrentAuthorizable().getID() + " (ignored)");
    } catch (RepositoryException | ActionExecutionException e) {
        actionResult = context.createActionResult();
        actionResult.logError(MessagingUtils.createMessage(e));
    }
    return actionResult;
}
Also used : Context(com.cognifide.apm.api.actions.Context) Action(com.cognifide.apm.api.actions.Action) User(org.apache.jackrabbit.api.security.user.User) RemoveParents(com.cognifide.apm.main.actions.removeparents.RemoveParents) ActionResult(com.cognifide.apm.api.actions.ActionResult) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.apm.api.exceptions.ActionExecutionException)

Example 2 with RemoveParents

use of com.cognifide.apm.main.actions.removeparents.RemoveParents in project APM by Cognifide.

the class DestroyUser method simulate.

@Override
public ActionResult simulate(Context context) throws ActionExecutionException {
    ActionResult actionResult;
    try {
        User user = context.getAuthorizableManager().getUser(userId);
        context.setCurrentAuthorizable(user);
        Action removeFromGroups = new RemoveParents(getGroups(user));
        ActionResult purgeResult = purge.simulate(context);
        ActionResult removeFromGroupsResult = removeFromGroups.execute(context);
        ActionResult removeResult = remove.simulate(context);
        actionResult = purgeResult.merge(removeFromGroupsResult, removeResult);
    } catch (RepositoryException | ActionExecutionException e) {
        actionResult = context.createActionResult();
        actionResult.logError(MessagingUtils.createMessage(e));
    }
    return actionResult;
}
Also used : Action(com.cognifide.apm.api.actions.Action) User(org.apache.jackrabbit.api.security.user.User) RemoveParents(com.cognifide.apm.main.actions.removeparents.RemoveParents) ActionResult(com.cognifide.apm.api.actions.ActionResult) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.apm.api.exceptions.ActionExecutionException)

Aggregations

Action (com.cognifide.apm.api.actions.Action)2 ActionResult (com.cognifide.apm.api.actions.ActionResult)2 ActionExecutionException (com.cognifide.apm.api.exceptions.ActionExecutionException)2 RemoveParents (com.cognifide.apm.main.actions.removeparents.RemoveParents)2 RepositoryException (javax.jcr.RepositoryException)2 User (org.apache.jackrabbit.api.security.user.User)2 Context (com.cognifide.apm.api.actions.Context)1