Search in sources :

Example 1 with Action

use of com.cognifide.apm.api.actions.Action 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 Action

use of com.cognifide.apm.api.actions.Action 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 3 with Action

use of com.cognifide.apm.api.actions.Action 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)

Example 4 with Action

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

the class CompositeAction method execute.

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

Aggregations

Action (com.cognifide.apm.api.actions.Action)4 ActionResult (com.cognifide.apm.api.actions.ActionResult)4 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