Search in sources :

Example 26 with ActionResult

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

the class RemoveFromGroup method process.

public ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = new ActionResult();
    List<String> errors = new ArrayList<>();
    Authorizable authorizable = null;
    try {
        authorizable = context.getCurrentAuthorizable();
        actionResult.setAuthorizable(authorizable.getID());
        LOGGER.info(String.format("Removing authorizable with id = %s from groups %s", authorizable.getID(), groupIds));
    } catch (ActionExecutionException e) {
        actionResult.logError(MessagingUtils.createMessage(e));
        return actionResult;
    } catch (RepositoryException e) {
        actionResult.logError(MessagingUtils.createMessage(e));
        return actionResult;
    }
    for (String id : groupIds) {
        try {
            Group group = AuthorizablesUtils.getGroup(context, id);
            if (execute) {
                group.removeMember(authorizable);
            }
            actionResult.logMessage(MessagingUtils.removedFromGroup(authorizable.getID(), id));
        } 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.cq.cqsm.api.actions.ActionResult) ArrayList(java.util.ArrayList) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException)

Example 27 with ActionResult

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

the class RemoveGroup method process.

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

Example 28 with ActionResult

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

the class SessionSave method process.

private ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = new ActionResult();
    if (execute) {
        try {
            SessionSavingMode savingMode = SessionSavingMode.valueOfMode(mode);
            SessionSavingPolicy savingPolicy = context.getSavingPolicy();
            savingPolicy.setMode(savingMode);
            actionResult.logMessage("Session saving mode set to: " + mode);
        } catch (IllegalArgumentException e) {
            actionResult.logError(MessagingUtils.createMessage(e));
        }
    }
    return actionResult;
}
Also used : ActionResult(com.cognifide.cq.cqsm.api.actions.ActionResult) SessionSavingMode(com.cognifide.cq.cqsm.core.sessions.SessionSavingMode) SessionSavingPolicy(com.cognifide.cq.cqsm.core.sessions.SessionSavingPolicy)

Example 29 with ActionResult

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

the class SetPassword method process.

private ActionResult process(final Context context, boolean execute) {
    ActionResult actionResult = new ActionResult();
    try {
        User user = context.getCurrentUser();
        actionResult.setAuthorizable(user.getID());
        LOGGER.info(String.format("Setting password for user with id = %s", user.getID()));
        if (execute) {
            user.changePassword(password);
        }
        actionResult.logMessage(MessagingUtils.newPasswordSet(user.getID()));
    } catch (RepositoryException | ActionExecutionException e) {
        actionResult.logError(MessagingUtils.createMessage(e));
    }
    return actionResult;
}
Also used : User(org.apache.jackrabbit.api.security.user.User) ActionResult(com.cognifide.cq.cqsm.api.actions.ActionResult) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException)

Example 30 with ActionResult

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

the class SetProperty method process.

private ActionResult process(final Context context, boolean simulate) {
    ActionResult actionResult = new ActionResult();
    try {
        Authorizable authorizable = context.getCurrentAuthorizable();
        actionResult.setAuthorizable(authorizable.getID());
        LOGGER.info(String.format("Setting property %s for authorizable with id = %s", nameProperty, authorizable.getID()));
        final Value value = context.getValueFactory().createValue(valueProperty);
        if (!simulate) {
            authorizable.setProperty(nameProperty, value);
        }
        actionResult.logMessage("Property " + nameProperty + " for " + authorizable.getID() + " added vith value: " + valueProperty);
    } catch (RepositoryException | ActionExecutionException e) {
        actionResult.logError(MessagingUtils.createMessage(e));
    }
    return actionResult;
}
Also used : ActionResult(com.cognifide.cq.cqsm.api.actions.ActionResult) Value(javax.jcr.Value) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) RepositoryException(javax.jcr.RepositoryException) ActionExecutionException(com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException)

Aggregations

ActionResult (com.cognifide.cq.cqsm.api.actions.ActionResult)30 RepositoryException (javax.jcr.RepositoryException)22 ActionExecutionException (com.cognifide.cq.cqsm.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 PathNotFoundException (javax.jcr.PathNotFoundException)3 Action (com.cognifide.cq.cqsm.api.actions.Action)2 SessionSavingPolicy (com.cognifide.cq.cqsm.core.sessions.SessionSavingPolicy)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 PermissionActionHelper (com.cognifide.cq.cqsm.foundation.permissions.PermissionActionHelper)2 PermissionException (com.cognifide.cq.cqsm.foundation.permissions.exceptions.PermissionException)2 ActionDescriptor (com.cognifide.cq.cqsm.api.actions.ActionDescriptor)1 ExecutionException (com.cognifide.cq.cqsm.api.exceptions.ExecutionException)1 Context (com.cognifide.cq.cqsm.api.executors.Context)1 Progress (com.cognifide.cq.cqsm.api.logger.Progress)1 ActionExecutor (com.cognifide.cq.cqsm.core.actions.executor.ActionExecutor)1