use of com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException 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;
}
use of com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException 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;
}
use of com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException 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;
}
use of com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException 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;
}
use of com.cognifide.cq.cqsm.api.exceptions.ActionExecutionException in project APM by Cognifide.
the class AuthorizablesUtils method getUserIfExists.
// *************************** USER UTILS **************************************
public static User getUserIfExists(Context context, String id) throws ActionExecutionException, RepositoryException {
if (checkIfRemoved(context, id)) {
return null;
}
Authorizable authorizable = context.getAuthorizables().get(id);
if (authorizable == null) {
authorizable = context.getUserManager().getAuthorizable(id);
}
if (authorizable == null) {
return null;
}
if (authorizable instanceof Group) {
throw new ActionExecutionException("Authorizable with id " + id + " exists but is a group not a user");
}
context.getAuthorizables().put(id, authorizable);
return (User) authorizable;
}
Aggregations