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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations