Search in sources :

Example 1 with Action

use of com.cognifide.cq.cqsm.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 = AuthorizablesUtils.getUser(context, userId);
        context.setCurrentAuthorizable(user);
        Action removeFromGroups = new RemoveFromGroup(getGroups(user));
        ActionResult purgeResult = purge.execute(context);
        ActionResult removeFromGroupsResult = removeFromGroups.execute(context);
        ActionResult removeResult = remove.execute(context);
        actionResult = new CompositeActionResult(purgeResult, removeFromGroupsResult, removeResult);
    } catch (RepositoryException | ActionExecutionException e) {
        actionResult = new ActionResult();
        actionResult.logError(MessagingUtils.createMessage(e));
    }
    return actionResult;
}
Also used : Action(com.cognifide.cq.cqsm.api.actions.Action) User(org.apache.jackrabbit.api.security.user.User) RemoveUser(com.cognifide.cq.cqsm.foundation.actions.removeuser.RemoveUser) CompositeActionResult(com.cognifide.cq.cqsm.foundation.actions.CompositeActionResult) ActionResult(com.cognifide.cq.cqsm.api.actions.ActionResult) RemoveFromGroup(com.cognifide.cq.cqsm.foundation.actions.removefromgroup.RemoveFromGroup) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException) CompositeActionResult(com.cognifide.cq.cqsm.foundation.actions.CompositeActionResult)

Example 2 with Action

use of com.cognifide.cq.cqsm.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 = AuthorizablesUtils.getUser(context, userId);
        context.setCurrentAuthorizable(user);
        Action removeFromGroups = new RemoveFromGroup(getGroups(user));
        ActionResult purgeResult = purge.simulate(context);
        ActionResult removeFromGroupsResult = removeFromGroups.execute(context);
        ActionResult removeResult = remove.simulate(context);
        actionResult = new CompositeActionResult(purgeResult, removeFromGroupsResult, removeResult);
    } catch (RepositoryException | ActionExecutionException e) {
        actionResult = new ActionResult();
        actionResult.logError(MessagingUtils.createMessage(e));
    }
    return actionResult;
}
Also used : Action(com.cognifide.cq.cqsm.api.actions.Action) User(org.apache.jackrabbit.api.security.user.User) RemoveUser(com.cognifide.cq.cqsm.foundation.actions.removeuser.RemoveUser) CompositeActionResult(com.cognifide.cq.cqsm.foundation.actions.CompositeActionResult) ActionResult(com.cognifide.cq.cqsm.api.actions.ActionResult) RemoveFromGroup(com.cognifide.cq.cqsm.foundation.actions.removefromgroup.RemoveFromGroup) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException) CompositeActionResult(com.cognifide.cq.cqsm.foundation.actions.CompositeActionResult)

Example 3 with Action

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

the class ScriptManagerImpl method parseIncludeDescriptors.

private List<ActionDescriptor> parseIncludeDescriptors(Script script, Map<String, String> definitions, List<Script> includes, ResourceResolver resolver) throws ExecutionException {
    final List<ActionDescriptor> descriptors = new LinkedList<>();
    LineIterator lineIterator = IOUtils.lineIterator(new StringReader(script.getData()));
    while (lineIterator.hasNext()) {
        String line = lineIterator.next();
        if (ScriptUtils.isAction(line)) {
            final String command = ScriptUtils.parseCommand(line, definitions);
            final ActionDescriptor descriptor = actionFactory.evaluate(command);
            final Action action = descriptor.getAction();
            descriptors.add(descriptor);
            if (action instanceof DefinitionProvider) {
                definitions.putAll(((DefinitionProvider) action).provideDefinitions(definitions));
            } else if (action instanceof ScriptProvider) {
                getIncludes(definitions, includes, resolver, descriptors, (ScriptProvider) action);
            }
        }
    }
    return descriptors;
}
Also used : Action(com.cognifide.cq.cqsm.api.actions.Action) DefinitionProvider(com.cognifide.cq.cqsm.api.actions.interfaces.DefinitionProvider) ScriptProvider(com.cognifide.cq.cqsm.api.actions.interfaces.ScriptProvider) ActionDescriptor(com.cognifide.cq.cqsm.api.actions.ActionDescriptor) StringReader(java.io.StringReader) LineIterator(org.apache.commons.io.LineIterator) LinkedList(java.util.LinkedList)

Aggregations

Action (com.cognifide.cq.cqsm.api.actions.Action)3 ActionResult (com.cognifide.cq.cqsm.api.actions.ActionResult)2 ActionExecutionException (com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException)2 CompositeActionResult (com.cognifide.cq.cqsm.foundation.actions.CompositeActionResult)2 RemoveFromGroup (com.cognifide.cq.cqsm.foundation.actions.removefromgroup.RemoveFromGroup)2 RemoveUser (com.cognifide.cq.cqsm.foundation.actions.removeuser.RemoveUser)2 RepositoryException (javax.jcr.RepositoryException)2 User (org.apache.jackrabbit.api.security.user.User)2 ActionDescriptor (com.cognifide.cq.cqsm.api.actions.ActionDescriptor)1 DefinitionProvider (com.cognifide.cq.cqsm.api.actions.interfaces.DefinitionProvider)1 ScriptProvider (com.cognifide.cq.cqsm.api.actions.interfaces.ScriptProvider)1 StringReader (java.io.StringReader)1 LinkedList (java.util.LinkedList)1 LineIterator (org.apache.commons.io.LineIterator)1